lunes, junio 16

Ejemplo para consultar un registro en la tabla alumnos de la base de datos cursophp

<html>
<body>
<?php
//CONSULTAR UN REGISTRO EN LA TABLA ALUMNOS DE LA BASE DE DATOS CURSOPHP
$con = mysql_connect("localhost","root","");
if (!$con)
{
echo('no hay coneccion: ' . mysql_error());
}
else
{
$doc = $_REQUEST['documento'];
$nom = $_REQUEST['nombres'];
$ape = $_REQUEST['apellidos'];
$fna = $_REQUEST['fechna'];
$sex = $_REQUEST['sexo'];
$dir = $_REQUEST['direccion'];
$tel = $_REQUEST['telefono'];
$ema = $_REQUEST['email'];
$db = 'cursophp';
echo $doc," ",$nom," ",$ape," ",$fna," ",$sex," ",$dir," ",$tel," ",$ema;
$con = mysql_connect("localhost","root","");
if($doc!="")
{
$sql="SELECT * FROM alumnos WHERE documento='$doc'";
}
mysql_select_db($db, $con);
$registro=mysql_query($sql,$con);
if ($row= mysql_fetch_array($registro))
{
echo "<table border = '1'> n";
echo "<tr>
<td>Documento</td>
<td>Nombre</td>
<td>Apellidos</td>
<td>Fecha Nacimiento</td>
<td>Sexo</td>
<td>Direccion</td>
<td>Telefono</td>
<td>E-mail</td>
</tr> n";
echo "<tr>
<td>".$row["documento"]."</td>
<td>".$row["nombres"]."</td>
<td>".$row["apellidos"]."</td>
<td>".$row["fechnac"]."</td>
<td>".$row["sexo"]."</td>
<td>".$row["direccion"]."</td>
<td>".$row["telefono"]."</td>
<td>".$row["email"]."</td>
</tr> n";
echo "</table> n";
} else {
echo "¡ No se ha encontrado ningún registro !";
}


echo "registro consultado";
}
mysql_close($con);
?>
</body>
</html>

No hay comentarios: