Click to See Complete Forum and Search --> : Problem with PHP


yopie
08-02-2003, 03:12 PM
Hi

I have these PHP code:

text.html

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=GET ACTION="text.php">
Who is your favourite author?
<INPUT NAME="Author" TYPE="TEXT">
<BR>
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>

and text.php:

<HTML>
<HEAD></HEAD>
<BODY>
Your favorite author is:
<?php
echo $Author;
?>
</BODY>
</HTML>

I saved the file at /usr/www/html
When I run text.html on my browser and enter at text box with Author name, the result always empty.
The result at browser:
Your favorite author is: (empty)

the script should display the name the author that I type.
Anyone see any typing mistake on my code, I copy exacly from text book!
I'm using RH 9, Mozilla 1.4, PHP ver 4.2.2. Httpd server is also running on the system.

Any clue?

Thanks

cfaun5
08-02-2003, 03:25 PM
Hi,

Your textbook is a little obsolete. In the newest version of php you need to specify where the value can be found. For exaple $_GET['Author'] instead of $Author. See the warning box at http://www.php.net/manual/en/language.variables.predefined.php.

As it says, if you insist (not a good idea...), you COULD turn register_globals to true in php.ini and the code will work unchanged...

-cfaun

Cerf
08-02-2003, 03:28 PM
You have to get the information form the browser

text.html is correct

<HTML>
<HEAD></HEAD>
<BODY>
<FORM METHOD=GET ACTION="text.php">
Who is your favourite author?
<INPUT NAME="Author" TYPE="TEXT">
<BR>
<BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>


but text.php has to be changed alittle

<HTML>
<HEAD></HEAD>
<BODY>
Your favorite author is:
<?php

$Author = $_REQUEST['Author'];
//$Author = $_GET['Author']; should also work


echo $Author;
?>
</BODY>
</HTML>

yopie
08-02-2003, 03:40 PM
Hi thanks for the help,

I add my text.php with
$Author = $_GET['Author']

and it works ok.

is it true that the textbook I use is obsolete? Damn, I guess I have to buy new book!! :(
Any sugestion for good, latest and up to date PHP book for beginner?

Thanks

Cerf
08-02-2003, 10:32 PM
Well, the php documentation is good at www.php.net. But at books go, I can't remember what books I used. I just made a small project for myself then tried to make it the best that I can

iDxMan
08-04-2003, 07:17 PM
Depends on when the book was written. Basically the php.ini setting register_globals is set to off. (which is a good idea) If you turn it back on, then $Author will be available.

-r

Cerf
08-04-2003, 08:09 PM
really, I got to try that ;)