Jump to content

Recommended Posts

<?


$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

Link to comment
https://forums.phpfreaks.com/topic/138780-solved-non-objectsundefined-variable/
Share on other sites

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.

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.