Help - Search - Member List - Calendar
Full Version: Undefined variable error Help
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
ChevyDriver
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_phpChapter3text.php on line 12.

Can someone tell me what I'm doing wrong?

Thanks.

Oli Filth
ChevyDriver said the following on 02/07/2005 01:34:
QUOTE
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_phpChapter3text.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


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.