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
HTML Forms not passing data to PHP
Moderator: General Moderators
HTML Forms not passing data to PHP
Last edited by Sniper007 on Fri May 14, 2004 5:12 pm, edited 1 time in total.
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
HTML / PHP Form code
Alright, here it is, straight out of the PHP manual:
The output I get is:
I just thought people would get annoyed if I made them read through something so basic...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: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>
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.
The output I get is:
Hi . You are years old.
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
try this (pay attention to the subtle differences)
the html - named whatever.html
the php file named action.php
Lite...
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>Code: Select all
<?PHP
$name1 = $_POSTї'name'];
$age = $_POSTї'age'];
echo "Hi, " . $name1 . "!";
echo "You are " . $age;
?>- WaldoMonster
- Forum Contributor
- Posts: 225
- Joined: Mon Apr 19, 2004 6:19 pm
- Contact:
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>