p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   Problems with Examples of Beginning with php4 Book (http://p2p.wrox.com/showthread.php?t=22733)

xtimox December 17th, 2004 02:52 AM

Problems with Examples of Beginning with php4 Book
 
Hello everyone, i just started learning php with the book that i wrote on the subject of the topic.

My problem is that some examples doesn't seem to work for me. . .

on the text.html and text.php example of Chapter 3 i get this error:

Your favorite author is:
Notice: Undefined variable: Author in C:\Archivos de programa\Abyss Web Server\htdocs\beginningphp\text.php on line 6

i also get the same error when i try to echo the $HTTP_USER_AGENT or any Environment Variable

Perhaps i need to configure something in the php.ini file???
[xx(]
Here are my codes:

text.php

<html>
<head></head>
<body>
Your favorite author is:
<?php
echo $Author;
?>
</body>
</html>

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>

Note that its happens the same with the codes that come with the book
What can i do to solve this???

Thanks in advice


[xx(]

kuehhc December 17th, 2004 03:52 AM

<html>
<head></head>
<body>
Your favorite author is:
<?php
echo $_GET['Author'];
?>
</body>
</html>

try this.

peg110 December 17th, 2004 02:01 PM

PHP essentially defines variables on the fly. Basically, as you assign a value to the variable, it defines it first and then assignes the value.

If no value is assinged to the variable, it does not get defined, thus an error.
As kuehhc points out if you use the SUPER GLOBAL of $_GET you will likely avoid the error (unless you submit with an EMPTY value in the field.) This is likely because in your PHP.INI file your register_globals is probably set to OFF. (This is a Safer method, but harder on the coding).

If you don't want to use the SUPER GLOBALS, then you can set the register_globals to ON and keep your original code.

To avoid this error when submitting an EMPTY value you could read http://p2p.wrox.com/topic.asp?TOPIC_ID=23664 which should help.

Good Luck

Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP


All times are GMT -4. The time now is 03:16 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.