dean7 Posted July 2, 2010 Share Posted July 2, 2010 Hi all, i've coded a script for my website but ive got a few error's in the code which i'm not sure how to sort: Notice: Undefined variable: carid in /home/www/**********/hts2.php on line 11 Notice: Undefined variable: fuel in /home/www/*******/hts2.php on line 13 Notice: Trying to get property of non-object in /home/www/*****/hts2.php on line 23 $timenow = time(); $username = $_SESSION['username']; $query=mysql_query("SELECT * FROM garage WHERE id='$carid' LIMIT 1"); // Line 11 $info = mysql_fetch_object($query); $query1=mysql_query("SELECT * FROM garage WHERE fuel='$fuel' LIMIT 2"); // Line 13 $info2 = mysql_fetch_object($query1); // ------------------- if($info->fuel < 15){ // Line 23 There the bit's of the code i'm having problems with. I've tried de-bugging it but carn't seem to sort it. Anyone know why I'm getting these error's? Thanks. Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/ Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 The undefined variable notices are simply alerting you that you're trying to use a variable that doesn't exist. As they don't exist though that then means your queries are returning 0 results, and so when you try to use $info->fuel you're being notified that the property "fuel" doesn't exist (as there's no results). Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080187 Share on other sites More sharing options...
dean7 Posted July 2, 2010 Author Share Posted July 2, 2010 So what would the easiest way to fix it be? Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080188 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 $carid and $fuel don't exist.. Where are they defined? Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080190 Share on other sites More sharing options...
dean7 Posted July 2, 2010 Author Share Posted July 2, 2010 For the fuel I did try defining it but as i done that it still gave me the same error: Notice: Trying to get property of non-object in /home/www/*****/hts2.php on line 23 Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080191 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 Because your queries aren't returning any results. You can check the number of results returned with mysql_num_rows - perform a check before you try creating/using the MySQL object. Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080192 Share on other sites More sharing options...
dean7 Posted July 2, 2010 Author Share Posted July 2, 2010 Ok, I tried it with the fuel and carid varibals , and the both ended 0, but how could I define the $carid varibal? Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080194 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 I don't know this is your code. Where are their values supposed to come from? Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080197 Share on other sites More sharing options...
dean7 Posted July 2, 2010 Author Share Posted July 2, 2010 Well when the user selects there car from there garage it put them in that car so they can do the races, but im just not sure how to sure how to retive that id. Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080201 Share on other sites More sharing options...
Adam Posted July 2, 2010 Share Posted July 2, 2010 Perhaps using $_GET? Be sure to sanitize input data before using it in your query though. Link to comment https://forums.phpfreaks.com/topic/206506-errors-within-code/#findComment-1080203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.