dean7 Posted September 19, 2010 Share Posted September 19, 2010 Hi all, sorry about the subject as I wernt sure what to call it but anyway, Ive re coded a feature on my website which gives the user a chance to race agienst the computer but ive got an error saying: Catchable fatal error: Object of class stdClass could not be converted to string in /home/www/*****/test/test.php on line 52 <?php session_start(); include ("../includes/config.php"); include ("../includes/functions.php"); logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username = $_SESSION['username']; $userstuff = mysql_query ("SELECT * FROM users WHERE username = '$username'") or die (mysql_error()); $user = mysql_fetch_object($userstuff); $garstu = mysql_query ("SELECT * FROM garage WHERE owner='$username'") or die (mysql_error()); $garage = mysql_fetch_object($garstu); $usercar = mysql_query ("SELECT carid FROM users WHERE username='$username'") or die (mysql_error()); $carin = mysql_fetch_object($usercar); $time= time() + 120; // Waiting time. if ($user->lastraceone > time()){ $left = $user->lastraceone - time(); echo "<center><b><font color=white>You Must Wait $left seconds before you race agian!</font></b></center>"; exit(); } // Use function to make sure there in a car.. function carcheck(){ if (empty($carin)){ echo ("You must be in a car before doing any races."); } else{ echo ("You are currently in: $carin."); } } // End function if (isset($_POST['race'])){ $race = $_POST['radiobutton']; carcheck(); //////////////////////////////////////// RACE 1 ///////////////////////////////////////////// if ($race == "1"){ // Rep gained $rand = rand(1000,10000); // Money gained $randmoney = rand(1000,15000); // Fuel used $randfuel = rand(3,10); mysql_query ("UPDATE users SET lastraceone = '$time' AND rep = 'rep+$rand' AND money = 'money+$randmoney' WHERE username='$username'") or die (mysql_error()); mysql_query ("UPDATE garage SET fuel = 'fuel-$randfuel' WHERE id = '$carin'") or die (mysql_error()); // Line 52 echo ("Well Done! You won: £$randmoney and $rand Rep. You also used $randfuel liters of fuel."); } /////////////////////////////////////// RACE 2 //////////////////////////////////////////// if ($race == "2"){ // Rep gained $random = rand(1000,10000); // Money gained $ranmoney = rand(1000,15000); // Fuel used $randomfuel = rand(3,10); mysql_query ("UPDATE users SET lastraceone = '$time' AND rep = 'rep+$random' AND money = 'money+$ranmoney' WHERE username='$username'") or die (mysql_error()); mysql_query ("UPDATE garage SET fuel = 'fuel-$randomfuel' WHERE id = '$carin'") or die (mysql_error()); echo ("Well Done! You won: £$ranmoney and $random Rep. You also used $randomfuel liters of fuel."); } } ?> <form action='' method='post' name='thisform'> Race along the Streets: <input name='radiobutton' type='radio' value='1'><br /> Race along A Drag Strip: <input name='radiobutton' type='radio' value='2'><br /> <input type='submit' name='race' Value='Race!'> mysql_query ("UPDATE garage SET fuel = 'fuel-$randfuel' WHERE id = '$carin'") or die (mysql_error()); // Line 52 Also line 52 is stated in the script I havent fully tested my script yet, while it not completly finished. But can anyone see why its giving me that error and how / or I can sort it please? Thanks for your help. Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted September 19, 2010 Share Posted September 19, 2010 you are setting $carin to an object here $carin = mysql_fetch_object($usercar); you'll need to get the information you want out of that object. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.