-
Problem with variables
Hi
I'm new to PHP and am having an issue.
Whenever i have a variable on the page I get the following error meesage:
Notice: Undefined variable: name in c:\inetpub\wwwroot\travel_db\test1.php on line 3
Welcome to our Web site, !
Page code is simply:
<HTML>
<?php
echo( "Welcome to our Web site, $name!" );
?>
</HTML>
Any thoughts??
-
I may not be reading this correctly, but it looks as if you are not defining your variable.
Try the following:
<HTML>
<?php
$name = "test user";
echo( "Welcome to our Web site, $name!" );
?>
</HTML>
Hope this helps, if not, please submit some more information and I'll look at it again.
-
Additionally
I would add that variables should be seperated from static text:
....
$name = "Fred Jones";
echo ("My name is ".$name.", I am fine!");
....
-
Your main problem isn't that the variable is undefined.... this should not stop your PHP code from working. The fact that you're getting "Notices" is of concern. I would create an .htaccess file and turn your error reporting settings down. On my production website, I have turned off all error reporting (No notices, warnings, etc... they're useless - my code works fine without the reporting... my users don't need to see it).
So, in order to do what I've suggested, create an .htaccess file in your main web html directory with the following within:
Code:
php_value error_reporting 0
php_value variables_order GPCS
php_value gpc_order GPC
php_flag asp_tags off
php_flag magic_quotes_gpc off
php_value output_buffering 4096
I hope this helps.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|