lunes, junio 16

Ejemplo para consultar todos los registros en la tabla alumnos de la base de datos cursophp

<html>
<body>
<?php
//CONSULTAR TODOS LOS REGISTROS EN LA TABLA ALUMNOS DE LA BASE DE DATOS CURSOPHP
$con = mysql_connect("localhost","root","");
if (!$con)
{
echo('no hay coneccion: ' . mysql_error());
}
else
{
$con = mysql_connect("localhost","root","");
$db="cursophp";
$sql="SELECT * FROM alumnos ";
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";
do {
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";
} while ($row = mysql_fetch_array($registro));
echo "</table> n";
} else {
echo "¡ No se ha encontrado ningún registro !";
}


echo "registros consultados";
}
mysql_close($con);
?>
</body>
</html>

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>

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

<html>
<body>
<form action="consultarregistro.php" method="GET">
<table border=0>
<tr>
<td>Documento :</td><td><input type="text" name="documento"></td></br>
</tr>
<tr>
<td>Nombres :</td><td><input type="text" name="nombres"></td></br>
</tr>
<tr>
<td>Apellidos :</td><td><input type="text" name="apellidos"></td></br>
</tr>
<tr>
<td>Fecha Nacimiento:</td><td><input type="text" name="fechna"></td></br>
</tr>
<tr>
<td>Sexo :</td><td><input type="text" name="sexo"></td></br>
</tr>
<tr>
<td>Direccion :</td><td><input type="text" name="direccion"></td></br>
</tr>
<tr>
<td>Telefono :</td><td><input type="text" name="telefono"></td></br>
</tr>
<tr>
<td>e-mail :</td><td><input type="text" name="email"></td></br>
<td><input type="submit" />
</tr>
</table>
</form>
</body>
</html>

viernes, junio 13

Ejemplo para insertar registro en una tabla llamada alumnos programa (insertarregistro.php)

<html>
<body>
<?php
//INSERTAR UN REGISTRO EN LA TABLA USUARIO DE LA BASE DE DATOS REGISTRO
$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="INSERT INTO alumnos (documento,nombres,apellidos,fechnac,sexo,direccion,telefono,email) VALUES ('$doc','$nom','$ape','$fna','$sex','$dir','$tel','$ema')";
}
mysql_select_db($db, $con);
mysql_query($sql,$con);
echo "registro insertado";
}
mysql_close($con);
?>
</body>
</html>

Ejemplo de formulario que captura datos para ser insertados

<html>
<body>
<form action="insertarregistro.php" method="GET">
<table border=0>
<tr>
<td>Documento :</td><td><input type="text" name="documento"></td></br>
</tr>
<tr>
<td>Nombres :</td><td><input type="text" name="nombres"></td></br>
</tr>
<tr>
<td>Apellidos :</td><td><input type="text" name="apellidos"></td></br>
</tr>
<tr>
<td>Fecha Nacimiento:</td><td><input type="text" name="fechna"></td></br>
</tr>
<tr>
<td>Sexo :</td><td><input type="text" name="sexo"></td></br>
</tr>
<tr>
<td>Direccion :</td><td><input type="text" name="direccion"></td></br>
</tr>
<tr>
<td>Telefono :</td><td><input type="text" name="telefono"></td></br>
</tr>
<tr>
<td>e-mail :</td><td><input type="text" name="email"></td></br>
<td><input type="submit" />
</tr>
</table>
</form>
</body>
</html>