conex.phtml
Código:
<?php function Conectarse() { if (!($link=mysql_connect("localhost","root","password"))) { echo "Error conectando a la base de datos."; exit(); } if (!mysql_select_db("prueba",$link)) { echo "Error seleccionando la base de datos."; exit(); } return $link; } ?>
procesar.phtml
Código PHP:
<?php
include("conex.phtml");
$link=Conectarse();
$id_prueba=$_GET['id_prueba'];
$nombre=$_GET['nombre'];
$apellido=$_GET['apellido'];
mysql_query("insert into prueba (id_prueba,Nombre,Apellido) values ('$id_prueba','$nombre','$apellido')",$link);
header("Location: insertar.reg.phtml");
?>
Código PHP:
<html>
<head>
<title>Ejemplo de PHP</title>
</head>
<body>
<H1>Insetar registro </H1>
<FORM ACTION="procesar.phtml">
<TABLE>
<TR>
<TD>id_prueba:</TD>
<TD><INPUT TYPE="text" NAME="id_prueba" SIZE="20" MAXLENGTH="30"></TD>
</TR>
<TR>
<TD>Nombre:</TD>
<TD><INPUT TYPE="text" NAME="nombre" SIZE="20" MAXLENGTH="30"></TD>
</TR>
<TR>
<TD>Apellido:</TD>
<TD><INPUT TYPE="text" NAME="apellido" SIZE="20" MAXLENGTH="30"></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" NAME="accion" VALUE="Grabar">
</FORM>
<hr>
<hr>
<?php
include("conex.phtml");
$link=Conectarse();
$result=mysql_query("select id_prueba, Nombre, Apellido from prueba",$link);
?>
<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>
<TR><TD> <B>id_prueba</B></TD> <TD> <B>Nombre</B></TD> <TD> <B>Apellido</B> </TD></TR>
<?php
while($row = mysql_fetch_array($result)) {
printf("<tr><td> %s</td> <td> %s</td> <td> %s </td></tr>", $row["id_prueba"], $row["Nombre"], $row["Apellido"]);
}
mysql_free_result($result);
mysql_close($link);
?>
</table>
</body>
</html>
plop no me deja poner link de ejemplo(que no contiene nada)
1 humberto al hacer click en 1 humberto aparezca el registro completo en una pantalla por ejemplo
por ejemplo
1 humberto y en otra pagina aparezca 1 humberto direccion correo etc