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
https://forums.phpfreaks.com/topic/200395-resource-id/
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
https://forums.phpfreaks.com/topic/200395-resource-id/#findComment-1051630
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
https://forums.phpfreaks.com/topic/200395-resource-id/#findComment-1051635
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.