Re: Recoger datos de un formulario.
| From: | Eliurkis | Date: | Sun, 17 Nov 2002 20:01:29 +0000 |
| Subject: | Re: Recoger datos de un formulario. | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-29390@lists.php.net to get a copy of this message | ||
Si utilizas el método POST y tienes register_globals en off deben de referirte a ella como
$_POST['email']
----- Original Message -----
From: Juan Luis
To: lista@phpes.com
Sent: Sunday, November 17, 2002 6:29 AM
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
file://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();}
file://select our database email
file://$db = mysql_select_db("email" , $connection)
file://insert the values of our form into our database
$sql_query = "INSERT INTO email VALUES (\"$name\",\"$email\")";
$results = mysql_query($sql_query);
file://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.