Page 1 of 1

HTML from 'post' method does not update PHP file

Posted: Thu Mar 06, 2003 2:23 pm
by Jackdaw
Am a newcomer to the world of Server Side programming and am learning about PHP via the 'in easy steps' series (this one authored by Mike McGrath). Books offer nothing in the way of support..........

got as far as the first Web form Example in the book - an example called fav.html/fav.php. In the html Form is an action command scripted as follows: <form action="fav.php" method="post">....... variables used within the form components are "username","colour" and "dish"......

These are referenced in the .php file as $username, $colour and $dish.

Am running Apache 1.3.27 on Win XP and everything seems to be configured correctly as described in the book yet when I try send the reguest to the server from the .html page instead of getting the values that should have been passed to the variable am getting complier error messages indicating that the variables are 'undefined'. My code for this and others are exactly as printed but the results are not as illustrated.

If you can figure out where I'm coming from on this (or if indeed you have this book yourself) perhaps you might be able to help!!!!! :?: :?:

Posted: Thu Mar 06, 2003 2:29 pm
by patrikG
The answer is probably in here:

viewtopic.php?t=511

Posted: Thu Mar 06, 2003 2:39 pm
by Jackdaw
Thanks Patrik G for the quick response on this.... will give it a shot and hope it'll work.............

Posted: Thu Mar 06, 2003 3:19 pm
by Jackdaw
HI again PatrikG

visited the link and tried using the $_['variable'] method as suggested but this didn't fix the problem (also tried tthe 'request' variable method without success.

The variables I'm trying to pass are not in an array - am trying probably the simplest example I can find to test the procedure and get these as a result:
"Notice: Undefined index: username in C:\Apache\htdocs\fav.php on line 6

Notice: Undefined index: color in C:\Apache\htdocs\fav.php on line 9 "

the second such suggests an array as it references index value........

No clue as to what is going on.

Am using PHP ver 4.2.3 on win XP Pro and have tried compiling to both IIS ver 5.1 and Apache 1.3.27 on port 80............

Nothing doin'..........................

Posted: Thu Mar 06, 2003 3:43 pm
by Sevengraff
when getting vars from a form, you need to use $_POST['variable'], so if you used this ....

<form action="fav.php" method="post">
<input type="text" name="fav_color">
<input type="submit" value="post your fav color">
</form>

then on fav.php, you could say

echo "Your favorite color is";
echo $_POST['fav_color'];

does this help?

Posted: Thu Mar 06, 2003 3:44 pm
by daven
try: $_POST['variable'] or $_GET['variable'], depending upon whether you are using form method=post or method=get, respectively.

Thanks

Posted: Thu Mar 06, 2003 4:37 pm
by Jackdaw
To PatrikG, SevenGraff and Daven ..............

thanks all for your replies....
went off line and solved the problem in the meantime (solution as below). Thanks for the helping hand and will have a look at your code maybe tomorrow....
as you can appreciated I'm wasted from trying to solve this one for nearly a week now so am glad for the breakthrough - the forum really helped and I guess I'll use it a good deal from here on - meanwhile can anyone suggest a good URL for a JSP forum?????

Heres my solution for what its worth.........

#<!--HTML CODE-->

<form action="simple.php" method="post"><br/>
Username
<input type="text" size="20" name="username"><hr/>
<input type="submit" value="Enter">
</form>

#<!--PHP CODE-->

<?php
$username = $_POST['username'];
echo("User entered: $username");
?>

Hasta Luego todos/ bis spaeter/ a bientot - time to get some sleep!!!!! :D