RE: [PHP-ES] Recoger datos de un formulario.
| From: | alan lavintman | Date: | Sun, 17 Nov 2002 17:06:22 +0000 |
| Subject: | RE: [PHP-ES] Recoger datos de un formulario. | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-29389@lists.php.net to get a copy of this message | ||
Fijate la sentencia sql de indicarle emn los campos que quieres meter
esas variables qeu tienen el dato,po rejemplo:
$sql="insert into email(nombre,email) values('$name','$email');";
el formulario esta bien y deberia recibir la variable;
-----Original Message-----
From: Juan Luis [mailto:juanluispgp@eresmas.com]
Sent: Domingo, 17 de Noviembre de 2002 09:30 a.m.
To: lista@phpes.com
Subject: [PHP-ES] Recoger datos de un formulario.
He desarrollado una página html con un formulario simple, al darle al
botón enviar llamo a una página php donde quiero recoger los datos
introducidos en el formulario y almacenarlos en una base de datos MySql.
Tenía entendido que si el campo nombre del formulario en la página html
inicial se llamaba "name", en la página php su valor se almacenaría en
la variable "$name", pero esto no me resulta porque esta variable
siempre está vacía. Os pongo el código del formulario y de la página
php, para que hagáis el favor de indicarme como recojo los valores:
<html>
<head>
<title>Lista de email</title>
</head>
<body>
<form action = "joinnemail.php" method = "post">
<table>
<tr><td>
Name : </td>
<td><input type = "text" name = "name">
</td></tr>
<tr><td>
Email :
</td>
<td><input type = "text" name = "email">
</td></tr>
<tr><td>
<input type = "submit" value = "join"></td>
<td><input type = "reset" value = "clear"></td></tr>
</table>
</form>
</body>
</html>
y la página joinnemail.php
<html>
<head>
<title>Lista de email</title>
</head>
<body>
<?php
//make a connection
$servidor = "localhost";
$usuario = "username";
$password = "";
$base_de_datos = "email";
$connection = @mysql_connect ($servidor,$usuario,$password);
if(!$connection) { echo ('Imposible conectarse con MySQL,'); exit();}
if(!@mysql_select_db($base_de_datos)) { echo ('Imposible conectarse con
la BD'); exit();}
//select our database email
//$db = mysql_select_db("email" , $connection)
//insert the values of our form into our database
$sql_query = "INSERT INTO email VALUES (\"$name\",\"$email\")";
$results = mysql_query($sql_query);
//display a thank you message and a link
echo ("Thank you for subscribing to our newsletter<br>");
echo ("<a href = 'index.htm'>Back to index page</a>");
?>
</body>
</html>
Gracias de antemano.
Saludos.