Passing Form Input to PHP

grooveagent

New Member
Hey all,

I just joined webdesignforum hoping to help and get help from other users. I just started working with PHP/mySQL and am excited about the possibilities of this combination.

Essentially my first project involves tryng to create an online sign-up. I've created an html form and assigned the input boxes to variables, then in the update.php file I'm converting the form input variables to php variables, then injecting these values into my mySQL database. Surprisingly, the php code connects to the db and creates an entry (which I thought was going to be the toughest part) but the fields are blank.

It appears that the form page is not passing the data entered to the php variables. I have created a couple of echo statements in the php file to display the contents of the variables from the form page, but similarly, they come up blank as if there is no data in the variable:

code:

echo "Thank you $name, you have been added to the sign up list." ;

result:

Thank you , you have been added to the sign up list.


I bet you can tell just by looking at the code what I've done wrong:

signup.html:
--------------

<html>
<head>
<title>ffwd online signup</title>
</head>

<body>
<form method="post" action="update.php">

Name: <br />
<input type="text" name="name" size="20" /><br />

City: <br />
<input type="text" name="city" size="20" /><br />

phone: <br />
<input type="text" name="phone" size="20" /><br />

email: <br />
<input type="text" name="email" size="20" /><br />

<input type="submit" value="submit" />

</form>

</body>
</html>


update.php
-------------

<?php
$name = $POST['name'];
$city = $POST['city'];
$phone = $POST['phone'];
$email = $POST['email'];

mysql_connect ("mysqlhost", "mysqlacountname", "mysqlpassword") or die ('Error: ' . mysql_error());
mysql_select_db ("mysqldb");

[database info changed to protect privacy]

echo "$name";

$query="INSERT INTO clientinfo (name, city, phone, email)VALUES ('".$name."', '".$city."','".$phone."','".$email."')";

mysql_query ($query) or die ('Error updating database');

echo "Thank you $name, you have been added to the sign up list." ;


?>


Thanks everyone!

GA
 

cmjvulavala

New Member
$name = $POST['name'];
$city = $POST['city'];
$phone = $POST['phone'];
$email = $POST['email'];

Needs to be changed to:

$name = $_POST['name'];
$city = $_POST['city'];
$phone = $_POST['phone'];
$email = $_POST['email'];

Basically $POST is a variable that you are making up yourself, whereas $_POST is a PHP system variable. That should sort out the problem for you :)
 

grooveagent

New Member
Thank you so much! I can't believe I missed those underscores and didn't notice. Sometimes it takes a fresh perspective...

Thanks again.

GA
 
Top