Forum Moderators: coopster

Message Too Old, No Replies

undefined variable.

         

Flolondon

10:09 pm on Feb 6, 2005 (gmt 0)

10+ Year Member



Notice: Undefined variable: username in c:\program files\easyphp1-7\www\fav.php on line 7

Notice: Undefined variable: colour in c:\program files\easyphp1-7\www\fav.php on line 11

please someone what does this mean please....cant seem to get my ...html file to work with my .php file...

jatar_k

10:23 pm on Feb 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



they are both just notices so I am guessing that the first time you use those vars is on the noted lines.

what is on line 7 and 11?

is it something like $username = 'somename'; and then the same for colour?

if so you can define them above where they are first used, something like

$username = '';
$colour = '';

that could be the answer but I am not totally sure with out seeing what is on those lines.

Flolondon

10:59 pm on Feb 6, 2005 (gmt 0)

10+ Year Member



<html><head><title> Your submission </title></head>
<body>

<img src="food.jpg" width="430" height="100">
<?

if( $username!=null)

{ echo ("Thanks for your selection $username<hr>"); }

if( ($colour!=null) && ($dish!=null) )

{

$msg="You really enjoy $dish<br>";
$msg.="- especially with a nice $colour wine";
echo($msg);

}

?>

</body></html>

hiya. please this is what i did and i got those undefined variables.. please help as its driving me mad

ergophobe

11:42 pm on Feb 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try this instead

if (isset($username))

This basically tests whether or not $username is defined.

if (!empty($username))

woudl test that it is both defined and has a non-zero value.

Flolondon

12:44 am on Feb 7, 2005 (gmt 0)

10+ Year Member



i tried it but it did not seem to work.

nsetiono

2:32 am on Feb 7, 2005 (gmt 0)



Hi
im new on this forum but i think i know why thats happened.
If your host use register_globals off you must use a command to catch http post variable
try use the code below :)

$variable = array("username","password");
for ($i = 0; $i <= 1; $i++)
{
if( isset($HTTP_GET_VARS[$variable[$i]]) ¦¦ isset($HTTP_POST_VARS[$variable[$i]]) )
{
$variable[$i] = ( isset($HTTP_POST_VARS[$variable[$i]]) )? $HTTP_POST_VARS[$variable[$i]] : $HTTP_GET_VARS[$variable[$i]];
}
else
{
$variable[$i] = '';
}
}

if (!empty($data))
{
setcookie("reg_id", "$data[0]");
setcookie("reg_username", "$data[1]");
mysql_close();
header("Location: index.php");
}
else
{
header("Location: index.php");
}

hope its help you

jatar_k

4:59 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld nsetiono