|
Posted by Oli Filth on 07/02/05 03:41
ChevyDriver said the following on 02/07/2005 01:34:
> I'm in the process of learning php and using WROX Beginning PHP 4 book and
> I'm in the chapter where it goes over Getting Data from the Client. The
> first page gets me to create this code:
>
> <html>
> <head>
> <title>Untitled</title>
> </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 the php page code is:
>
> <html>
> <head>
> <title>Untitled</title>
> </head>
>
> <body>
>
> Your favourite author is:
> <?php
> echo $Author;
> ?>
>
> </body>
> </html>
>
> When I process the page in EI, I get the following message: Notice:
> Undefined variable: Author in E:\learning_php\Chapter3\text.php on line 12.
>
> Can someone tell me what I'm doing wrong?
>
If the book is telling you to do it like that, then it's time to throw
the book away. It's outdated, and PHP has moved on since then.
The correct syntax ("correct" as in "less of a security risk, and not
deprecated") for obtaining data that came from forms is $_GET['Author']
rather than $Author. Most PHP setups don't allow the use of $Author, as
you've just found out!
For an explanation why, see the PHP manual, at
http://www.php.net/manual/security.globals.php
--
Oli
Navigation:
[Reply to this message]
|