HTML Forms not passing data to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sniper007
Forum Newbie
Posts: 17
Joined: Tue May 11, 2004 8:43 pm

HTML Forms not passing data to PHP

Post 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
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

Post by malcolmboston »

we can't help you unless you post the code your using
Sniper007
Forum Newbie
Posts: 17
Joined: Tue May 11, 2004 8:43 pm

HTML / PHP Form code

Post 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&#1111;'name']; ?>.
You are <?php echo $_POST&#1111;'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.
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Post 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&#1111;'name'];
$age = $_POST&#1111;'age'];
echo "Hi, " . $name1 . "!";
echo "You are " . $age;

?>
Lite...
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post 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>
Sniper007
Forum Newbie
Posts: 17
Joined: Tue May 11, 2004 8:43 pm

Post by Sniper007 »

THANK YOU!!! It worked!
:D

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.
Post Reply