Hola a todos , estoy intentando crear un php que devuelva el telefono de una tabla de una base de datos , insertando el nombre y apellidos pero me da errores por todos lados y no consigo entenderlo
la tabla es esta
http://subefotos.com/ver/?0773b601f9d17b8cc9392caad95cf9edo.png
el formulario
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<label for="textfield"></label>
<form id="form1" name="form1" method="post" action="recibe telefonos.php">
<p>Busqueda de telefonos</p>
<p>Nombre</p>
<p>
<label for="textfield2"></label>
<input type="text" name="nombre" id="textfield2" />
</p>
<p>Apellidos</p>
<p>
<label for="textfield3"></label>
<input type="text" name="apellidos" id="textfield3" />
</p>
<p>
<input type="submit" name="button" id="button" value="Buscar" />
</p>
</form>
</body>
</html>
el php
<?php$nombre=$_POST['nombre'];$apellido = $_POST['apellidos'];?>
<?php$connect=mysqli_connect("127.0.0.1","jorge","","prueba");if ($connect) {echo "conexion realizada.</br>"; $selec= "select telefono from persona where apellidos='$apellido' and nombre='$nombre'" ; $telefono=mysqli_query($connect,$selec); if ($telefono==""){ echo " no hay ningun telefono con ese nombre y apellidos ";} else {echo "el telefono de ".$nombre." ".$apellido." es ".$telefono;} if (mysqli_close($connect)){echo " </br> desconexion realizada ";} } else {echo "error en la desconexion ";}?>
Gracias y un abrazo.
A la orden!
formulario de carga de los datos
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<link type="text/css" rel="stylesheet" href="estilos.css" />
</head>
<body>
<?phpinclude "cabecera.html"?>
<div id="principal">
<form method="post" action="insertar agenda.php">
<h1>Introduzca sus datos</h1>
<p><br />
Nombre<input name="nombre" type="text" />
</p>
<p><br />
apellidos<input name="apellidos" type="text" />
</p>
<p><br />
telefono<input name="tlfno" type="text" />
</p>
<p><br />
e-mail<input name="email" type="text" /><br />
</p>
<input name="" type="submit" value="Registrar" />
</form>
</div>
<?phpinclude "pie.html"?>
</body>
</html>
PHP que inserta los datos en la bbdd
<?php$connect=mysqli_connect("localhost","root","","academia");if ($connect) { echo "conexion exitosa. <br />"; $id='';//auto incrementa sola el compo id , tambien se puede usar auto_increment y `rimary key al crear la tabla $nombre= $_POST ['nombre']; $apellidos= $_POST ['apellidos']; $telefono= $_POST ['tlfno']; $email= $_POST ['email']; $consulta="insert into agenda values ('$id','$nombre','$apellidos',$telefono,'$email')"; $resultado=mysqli_query($connect,$consulta); if ($resultado) { echo "perfil almacenado. <br />"; } else { echo "error en la ejecución de la consulta. <br />"; } if (mysqli_close($connect)){ echo "desconexión realizada. <br />"; } else { echo "error en la desconexión"; }}?>
la hoja de estilos y la cabecera y el pie no los creo necesarios , ademas son facilitos.
Espero que ayude , un abrazo.