Jump to content

Resource id?


dean7

Recommended Posts

Hi all, ive got got this piece of code:

 

if ($fetch->money < $price){
echo "You dont have enough money to upgrade your car!";
}elseif ($fetch->money >= $price){

$new_money=$fetch->money-$price;
$new_up="$next_1-$upgrades[1]-$upgrades[2]-$upgrades[3]-$upgrades[4]-$upgrades[5]-$upgrades[6]-$upgrades[7]";
mysql_query("UPDATE garage SET upgrades='$new_up' WHERE id='$car' AND owner='$username'");
mysql_query("UPDATE users SET money='$new_money' WHERE username='$username'");
$speed = mysql_query("SELECT speed FROM garage WHERE id='$car' AND owner='$username'");
mysql_query("UPDATE garage SET speed='$speed+5' WHERE id='$car' AND owner='$username'") OR DIE ("Couldnt add 5mph");
echo "Car upgraded!";
}
}

But there seems to be a problem with it.

When i echo the speed out from database it says:  Resource id #15+5 MPH.

Allthough what I though it should do is update that table but add 5 to the current ammout.

Anyone know why its inserting : Resource id #15+5 MPH into the database instaid of 5?

 

Thanks

Link to comment
Share on other sites

This should work:

 

$result = mysql_fetch_assoc(mysql_query("SELECT speed FROM garage WHERE id='$car' AND owner='$username'")) OR DIE(mysql_error());
$speed = $result['speed'];
mysql_query("UPDATE garage SET speed='$speed+5' WHERE id='$car' AND owner='$username'") OR DIE ("Couldnt add 5mph");
echo "Car upgraded!";

Link to comment
Share on other sites

This should work:

 

$result = mysql_fetch_assoc(mysql_query("SELECT speed FROM garage WHERE id='$car' AND owner='$username'")) OR DIE(mysql_error());
$speed = $result['speed'];
mysql_query("UPDATE garage SET speed='$speed+5' WHERE id='$car' AND owner='$username'") OR DIE ("Couldnt add 5mph");
echo "Car upgraded!";

I changed that but it made no different :S.

But ive also found out that everytime i add a new part to the car it adds another +5 at the end.

So example: Resource id #15+5+5 MPH

Link to comment
Share on other sites

why not simply add 5 to it without having to select it

mysql_query("UPDATE garage SET speed=speed + 5 WHERE id='$car' AND owner='$username'") OR DIE ("Couldnt add 5mph");

 

that'll add 5 to the current value without having to do a whole other query

Link to comment
Share on other sites

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.