Page 1 of 1
HTML Forms not passing data to PHP
Posted: Fri May 14, 2004 1:14 pm
by Sniper007
I've read through the section in the manual several times. I copied and pasted their code into two files. An index.php (where the HTML form is contained) and the action.php (where the submitted text should be output). But no matter what tutorial I read and copy from (I've done several Googles) the submitted HTML form never passes the data to the server. It always displays an empty string. Could someone at least post WORKING HTML form and PHP display files, or please walk me through the process?
EDIT: foo.php => action.php
Posted: Fri May 14, 2004 1:23 pm
by malcolmboston
we can't help you unless you post the code your using
HTML / PHP Form code
Posted: Fri May 14, 2004 5:11 pm
by Sniper007
Alright, here it is, straight out of the PHP manual:
Code: Select all
<form action="action.php" method="post">
Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
<input type="submit" />
</form>
There is nothing special about this form. It is a straight HTML form with no special tags of any kind. When the user fills in this form and hits the submit button, the action.php page is called. In this file you would write something like this:
Example 2-7. Printing data from our form
Code: Select all
Hi <?php echo $_POSTї'name']; ?>.
You are <?php echo $_POSTї'age']; ?> years old.
A sample output of this script may be:
Hi Joe. You are 22 years old.
I just thought people would get annoyed if I made them read through something so basic...
The output I get is:
Hi . You are years old.
Posted: Fri May 14, 2004 9:31 pm
by litebearer
try this (pay attention to the subtle differences)
the html - named whatever.html
Code: Select all
<html>
<head>
<head>
<body bgcolor="#ffffff" text="#261a1c" link="#ff2b2b" vlink="#800080" alink="#ff0000">
<form action="action.php" method="post">
Your name: <input type="text" name="name" size="10" maxlength="20" value=""><br>
Your age : <input type="text" name="age" size="2" maxlength="2" value=""><br>
<input type="submit" value="submit">
</form>
</body>
</html>
the php file named action.php
Code: Select all
<?PHP
$name1 = $_POSTї'name'];
$age = $_POSTї'age'];
echo "Hi, " . $name1 . "!";
echo "You are " . $age;
?>
Lite...
Posted: Sat May 15, 2004 12:36 am
by WaldoMonster
You only have to remove the slashes from your example code:
Code: Select all
<form action="test.php" method="post">
Your name: <input type="text" name="name">
Your age: <input type="text" name="age">
<input type="submit">
</form>
Posted: Sat May 15, 2004 9:25 pm
by Sniper007
THANK YOU!!! It worked!
The only quirk is that I needed to type in the full web address to the action.php file. Otherwise it kept on displaying as a text document in my browser, showing all the code.