Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/07/2002, 08:56
NRLABS
 
Fecha de Ingreso: febrero-2002
Ubicación: Chile
Mensajes: 1.573
Antigüedad: 22 años, 2 meses
Puntos: 2
Re: formularios con php

facil!!
un ejemplo:

usuarios.lycos.es/nicosoft_corp/anadir.php
usuarios.lycos.es/nicosoft_corp
utilizamos una base sql y una tabla (nicolas) dos campos nombre y apellido.


Para añadir registros.

<html>
<head>
<title>Añadir registros - NR Labs - Admin panel</title>
</head>
<body>

<FORM ACTION="procesar.php">
<TABLE>
<TR>
<TD>Nombre:</TD>
<TD><INPUT TYPE="text" NAME="nombre" SIZE="20" MAXLENGTH="30"></TD>
</TR>
<TR>
<TD>Apellidos:</TD>
<TD><INPUT TYPE="text" NAME="apellidos" SIZE="20" MAXLENGTH="30"></TD>
</TR>
</TABLE>
<INPUT TYPE="submit" NAME="accion" VALUE="Grabar">
</FORM>


</body>
</html>


para procesarlos.

<html>
<head>
</head>
<body>

<?php
include("conectar.php");
$link=Conectarse();
mysql_query("insert into nicolas (Nombre,Apellidos) values ('$nombre','$apellidos')",$link);

?>


</body>
</html>

para conectarse.


<html>
<head><title>NR Labs, Panel de administración</title>
</head>
<body>
<?php
function Conectarse()
{
if (!($link=mysql_connect("localhost",&quot ;nombre","passs")))
{
echo "Error conectando a la base de datos";
exit();
}
if (!mysql_select_db("nombre",$link))
{
echo "Error seleccionando la base de datos";
exit();
}
return $link;
}
?>
</body>
</html>


y para ver los datos.


<html>
<head>
<title>Consultas (NR Labs - Panel Desing)</title>
</head>
<body>
<H1>Prueba del panel de administración</H1>
<?php
include("conectar.php");
$link=Conectarse();
$result=mysql_query("select * from nicolas",$link);
?>
<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1>
<TR><TD> Nombre</TD><TD> Apellidos </TD></TR>
<?php

while($row = mysql_fetch_array($result)) {
printf("<tr><td> %s</td><td> %s </td></tr>", $row["Nombre"],$row["Apellidos"]);
}
mysql_free_result($result);
mysql_close($link);
?>
</table>
</body>
</html>