Jump to content

Recommended Posts

Hi all, ive got a problem with this script, well part of it. Its the same script which i needed help with the other day which i manged to sort, but now its came to a bit im not to sure how to fix.

 

$username = $_SESSION['username'];
$location = $fetch_users_data->location;
$carin = mysql_query("SELECT carin FROM users WHERE username = '$username'");// not sure about
$car1 = mysql_query("SELECT * FROM garage WHERE owner = '$username' AND carin = '$carin'");; // not sure about
$car = mysql_fetch_object($car1);

-------------------------------------------------------------------

if ($car->speed <= "39"){ // Line 63
echo ("Your car must be 40mph or faster to win any races.");
}elseif ($car->speed >= "40"){
// Code not needed at the mintue
}

 

Though that little part of the script, its giving me an error which says :

Notice: Trying to get property of non-object in /home/www/*****/****.php on line 63

 

Anyone know why it giving me that error?

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/204721-property-of-non-object/
Share on other sites

$username = $_SESSION['username'];
$location = $fetch_users_data->location;
$carin = mysql_query("SELECT carin FROM users WHERE username = '$username'") or die(mysql_error()); // not sure about
$car1 = mysql_query("SELECT * FROM garage WHERE owner = '$username' AND carin = '$carin'") or die(mysql_error()); // not sure about
if(!$car = mysql_fetch_object($car1)) {
    die("Could not fetch row data - MySQL Error: ".mysql_error());
}

-------------------------------------------------------------------

if ($car->speed <= "39"){ // Line 63
echo ("Your car must be 40mph or faster to win any races.");
}elseif ($car->speed >= "40"){
// Code not needed at the mintue
}

$username = $_SESSION['username'];
$location = $fetch_users_data->location;
$carin = mysql_query("SELECT carin FROM users WHERE username = '$username'") or die(mysql_error()); // not sure about
$car1 = mysql_query("SELECT * FROM garage WHERE owner = '$username' AND carin = '$carin'") or die(mysql_error()); // not sure about
if(!$car = mysql_fetch_object($car1)) {
    die("Could not fetch row data - MySQL Error: ".mysql_error());
}

-------------------------------------------------------------------

if ($car->speed <= "39"){ // Line 63
echo ("Your car must be 40mph or faster to win any races.");
}elseif ($car->speed >= "40"){
// Code not needed at the mintue
}

I done that and it echoed:

 

Could not fetch row data - MySQL Error:

 

But dont know why it carnt fetch the data?

Have you tried debugging it?  Lol.

 

Print out the SQL query and put it directly in to MySQL.  See what happens.

 

Print out a mysql_error() right after each mysql_query() function.

 

Also, I see you commented a "not sure about" in your source code.  If you're not sure about something, why not look it up in the manual?

 

Oh, and Google is always your friend: http://www.google.com/search?q=debugging+mysql+php&ie=utf-8&oe=utf-8&aq=t&client=firefox-a&rlz=1R1GGLL_en___US369

Have you tried debugging it?  Lol.

 

Print out the SQL query and put it directly in to MySQL.  See what happens.

 

Print out a mysql_error() right after each mysql_query() function.

 

Also, I see you commented a "not sure about" in your source code.  If you're not sure about something, why not look it up in the manual?

 

Oh, and Google is always your friend: http://www.google.com/search?q=debugging+mysql+php&ie=utf-8&oe=utf-8&aq=t&client=firefox-a&rlz=1R1GGLL_en___US369

Yeah ive tryed de-bugging it, been trying for ages lol. Rather new to php aswell so that dont help. Yeah were I commented "Not sure about" is part which im not sure if it would work.

As I think mattal999 was getting at, you're trying to use mysql_fetch_object() on either an empty resource, or a boolean value (mysql_query() returns false on error). You should validate that rows were actually returned from the SELECT statement with mysql_num_rows, before trying to fetch the data object. For example:

 

if (mysql_num_rows($carl) > 0)
{
    $car = mysql_fetch_object($carl);
}

 

If you still receive some PHP errors for using mysql_num_rows(), you have an error in your syntax.

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.