HTML from 'post' method does not update PHP file

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
Jackdaw
Forum Newbie
Posts: 7
Joined: Thu Mar 06, 2003 2:23 pm

HTML from 'post' method does not update PHP file

Post 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!!!!! :?: :?:
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

The answer is probably in here:

viewtopic.php?t=511
Jackdaw
Forum Newbie
Posts: 7
Joined: Thu Mar 06, 2003 2:23 pm

Post by Jackdaw »

Thanks Patrik G for the quick response on this.... will give it a shot and hope it'll work.............
Jackdaw
Forum Newbie
Posts: 7
Joined: Thu Mar 06, 2003 2:23 pm

Post 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'..........................
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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?
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

try: $_POST['variable'] or $_GET['variable'], depending upon whether you are using form method=post or method=get, respectively.
Jackdaw
Forum Newbie
Posts: 7
Joined: Thu Mar 06, 2003 2:23 pm

Thanks

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