Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.