Jump to content

Undefined variable, even when there isnt?


dean7

Recommended Posts

Hi all, Ive had alot of problem with one script latly but I carnt see what it accually causing the problems.

 

My script is giving me an error saying:

 

Notice: Undefined variable: carin in /home/www/*****.com/test/test.php on line 23

 

And:

 

Notice: Trying to get property of non-object in /home/www/*****.com/test/test.php on line 23

 

My Code:

 

$carin1 = mysql_query ("SELECT carid FROM users WHERE username='$username'") or die (mysql_error());			$carin = mysql_fetch_object($carin1);// Use function to make sure there in a car..function carcheck(){if ($carin->carid == ''){ // LINE 23echo ("You must be in a car before doing any races.");}else{echo ("You are currently in: $carin->carid");}exit();}	// End function		

 

 

Where its saying ive got an undefined variable carin I accually havent as it is defined. :S

 

Anyone see what is wrong with that part of my script?.

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/213988-undefined-variable-even-when-there-isnt/
Share on other sites

to clarify, either:-

 

function carcheck(){global $carin;if ($carin->carid == ''){ // LINE 23

 

 

or, pass it as a parameter into the function

 

 

function carcheck($carin){if ($carin->carid == ''){ // LINE 23

 

 

Simple!

 

Rw

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.