AsiaUnderworld Posted December 29, 2008 Share Posted December 29, 2008 <? $id = secure($_SESSION['user_id']); $id = $id[0]; $sql = "SELECT * FROM user_stats WHERE user_id='$id'"; $result = mysql_query($sql); $result2 = mysql_fetch_assoc($result); $firstcheck = "SELECT ticketprice FROM airport WHERE id='1' "; $firstcheck1 = "SELECT ticketprice FROM airport WHERE id='2' "; $firstcheck2 = "SELECT ticketprice FROM airport WHERE id='3' "; $firstcheck3 = "SELECT ticketprice FROM airport WHERE id='4' "; $price = mysql_query($firstcheck) or die(mysql_error()); $price1 = mysql_query($firstcheck1) or die(mysql_error()); $price2 = mysql_query($firstcheck2) or die(mysql_error()); $price3 = mysql_query($firstcheck3) or die(mysql_error()); if(isset($_POST['travel'])) if (isset($_POST['radio'])) { $radio=strip_tags($_POST['radio']); if (!ereg('[^0-9]',$radio)) { if ($radio == "1") { $costs = $price ; $to = "Chicago"; } elseif ($radio == "2") { $costs = $price1; $to = "Detroit"; } elseif ($radio == "3") { $costs = $price2 ; $to = "New York"; } elseif ($radio == "4") { $costs = $price3 ; $to = "Washington"; } } if ($fetch->lasttravel > time()) echo "You cannot travel for another ".maketime($result2->lasttravel)." "; elseif ($costs > $result2->money) echo " You don't have enough money for this ticket" ; } elseif ($costs <= $result2->money) { } elseif ($to == $result2->location_id) echo " You are already in this city. " ; { } if ($to != $result2->location_id) { $flightcosts = $result2->money - $costs; $now = time() + 3600; mysql_query("UPDATE user_stats SET location_id='$to', money='$flightcosts' , lasttravel='$now' WHERE user_id='$id'"); } ?> The page says 15:17 pm: Notice: Trying to get property of non-object in /home/djwdesi/public_html/gangster/airport.php on line 80 15:17 pm: Notice: Undefined variable: to in /home/djwdesi/public_html/gangster/airport.php on line 80 Those lines are } if ($to != $result2->location_id) { When i click the submitbutton to travel it still does nothing, whats wrong? thanks Quote Link to comment https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/ Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 Add this and see what you get: <?php $result = mysql_query($sql) or die('Invalid query: ' . mysql_error() . "\n"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/#findComment-725635 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Don't you mean elseif ($to == $result2->location_id) { echo " You are already in this city. " ; } Not: elseif ($to == $result2->location_id) echo " You are already in this city. " ; { } Quote Link to comment https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/#findComment-725636 Share on other sites More sharing options...
AsiaUnderworld Posted December 29, 2008 Author Share Posted December 29, 2008 tried both and nothing changed Quote Link to comment https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/#findComment-725643 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 OH, duh. if ($to != $result2->location_id) should be if ($to != $result2['location_id']) Quote Link to comment https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/#findComment-725658 Share on other sites More sharing options...
AsiaUnderworld Posted December 29, 2008 Author Share Posted December 29, 2008 that doesnt do anything, just makes more errors Quote Link to comment https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/#findComment-725668 Share on other sites More sharing options...
flyhoney Posted December 29, 2008 Share Posted December 29, 2008 Well, when you call mysql_fetch_assoc() on a mysql result it returns an associative array, not an object. Hence the "assoc". You are referencing an associative array as an object which is why you are getting the errors. Either use mysql_fetch_object() or start referencing $result2 as an associative array. Quote Link to comment https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/#findComment-725672 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.