Page 1 of 1

Problem with this tutorial...

Posted: Wed Mar 12, 2003 5:38 pm
by Random
Okay, I just got a book..."SAMS Teach Yourself PHP in 24 Hours". I am on hour 9 "How to create and retrieve user data". It shows the following things:

Code: Select all

<HTML>
<HEAD>
<TITLE>Listing 9.2 a Simple HTML Form</TITLE>
</HEAD>
<BODY>
<form action="process.php">
<input type="text" name="user">
<br>
<textarea name="address" rows="5" cols="40">
</textarea>
</FORM>
</BODY>
</HTML>
and the process.php is this:

Code: Select all

<HTML>
<HEAD>
<TITLE>Listing 9.3 Reading input from the form in Listing 9.2</TITLE>
</HEAD>
<BODY>
<?php
print "Welcome <b>$user</b><P>\n\n";
print "Your address is:<P>\n\n<b>$address</b>";
?>
</BODY>
</HTML>
This was copied word for word from the book. When I enter my name and address in the boxes, it comes up on the process.php page like this:

Welcome
Your address is:

and leaves it blank. Please post how to fix and what the book is missing. Thanks

Posted: Wed Mar 12, 2003 5:48 pm
by redJag
changing it to "welcome ".$POST_[user]; should work. although you might have to define the method on the HTML page. try that though.

Posted: Wed Mar 12, 2003 5:49 pm
by Random
ok thanks I will try that and post how it goes...kinda odd that this well of a book, and how many it sells, forgot to include that... Maybe he will make a version 2.0 of his book :D

Posted: Wed Mar 12, 2003 6:04 pm
by Random
did i write this right?

Code: Select all

<HTML>
<HEAD>
<TITLE>.: Processing Form :.</TITLE>
</HEAD>
<BODY>
<?PHP
print "Welcome <b>$_POST&#1111;'user']</b><P>\n\n";
print "Your address is:<P>\n\n<b>$_POST&#1111;'address']</b>";
?>
</BODY>
</HTML>

Posted: Wed Mar 12, 2003 6:12 pm
by redJag
yes, for some reason i wrote it wrong, but you have it down correctly. if thats not working, set the method in the form to POST and it should work perfectly.

Posted: Wed Mar 12, 2003 6:13 pm
by Random
ok nevermind...i reread your thing...

Code: Select all

<HTML>
<HEAD>
<TITLE>.: Processing Form :.</TITLE>
</HEAD>
<BODY>
<?PHP
print "Welcome <b>".$_POST&#1111;'user']."</b><P>\n\n";
print "Your address is:<P>\n\n<b>".$_POST&#1111;'address']."</b>";
?>
</BODY>
</HTML>

Posted: Thu Mar 13, 2003 12:37 am
by net7
Works both ways, and the book didn't have it wrong. See older versions of php had it so if there was a variable passed by a form or URL you could use the variable in a script with $variable. Now you have to use

$_POST['variable']
$_GET['variable']
$_REQUEST['variable']

depending on which method you defined in the form.

Posted: Thu Mar 13, 2003 2:01 am
by twigletmac
For more information:
viewtopic.php?t=511

Mac