/    Sign up×
Community /Pin to ProfileBookmark

udefined variables

Hi, I’m new in PHP and I’m creating my scripts on Win XP platform. PHP scripts alone works fine but when I create forms in HTML and try to Post/Get and process them in PHP, I get the following error message:

undefined variable: “varname” “c:/Program files/EasyPHP 1.8/www/filename.php” on line: 8

Please if anyone came across this kind of an error can you please assist.

Regards

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@pcthugJan 26.2007 — Unless you are sure that a variable exists, you should always determine whether a variable [url=http://www.php.net/isset]is set[/url] before calling it.
[code=php]
if (isset($varname))
// you may now safely call varname
[/code]
Copy linkTweet thisAlerts:
@MrCoderJan 26.2007 — Another tip..

You can replace this..

[code=php]if(isset($myValue))
{
if($myValue > 0)
{
echo "MyValue > 0";
}
}[/code]


With this..

[code=php]if(isset($myValue) && $myValue > 0)
{
echo "MyValue > 0";
}[/code]


This will also resolve the error, since IF statments are left to right priority so if $myValue was not set the "$myValue > 0" never gets executed and no error is generated.
Copy linkTweet thisAlerts:
@NightShift58Jan 26.2007 — undefined variable: "varname" "c:/Program files/EasyPHP 1.8/www/filename.php" on line: 8[/QUOTE]Could it be that you simply forgot to put a [B]$[/B] in front of the variable name?
Copy linkTweet thisAlerts:
@NogDogJan 26.2007 — Note that another common cause of that notice message is when you use a combined operator to assign a value to a variable which has not yet been initialized:
[code=php]
$string .= "text";
$value += 5;
[/code]

If you initialize the variables first, then you won't get the notice:
[code=php]
$string = '';
$string .= "text";

$value = 0;
$value += 5;
[/code]
Copy linkTweet thisAlerts:
@NightShift58Jan 26.2007 — [code=php]<?php
print "Error Reporting: " . ini_get("error_reporting") . "<br>";

$string .= "text";
print $string . "<br>";

$value += 5;
print $value . "<br>";
?>
[/code]

See: http://www.nightshift58.com/webdev/test_undef_var.php

???

EDIT: It reports the undefined variable with error_reporting(E_ALL)... which could be caused by either the possibilities mentioned by NogDog or the missing [B]$[/B].
Copy linkTweet thisAlerts:
@S__J__MasweuauthorJan 29.2007 — Thanks for the replies, I really appreciate it but the errors still persist. Have you guys worked with $HTTP_*_VARS? This is where my problem lies. I created a HTML file and I'm using GET to .php file. A user will select a color form the radio button named color and click submit button on the HTML file, which will change the bgcolor of the page depending on which color was selected. Another book told me about register_global in the php.ini,how do you set this things? Remember I'm using EasyPHP 1-8.
Copy linkTweet thisAlerts:
@NogDogJan 29.2007 — EDIT: Nevermind---I was confused by the manual.
×

Success!

Help @S__J__Masweu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...