Jump to content

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in


Recommended Posts

Hi guys, I appreciate this is just a common error, ive searched through an found many threads with the same error and tried using the mysql error func but it was of no joy,

Im still fairly fresh to php itself, but im fairly familar with C structures in general, i think im just being blind on what im doing.

trying to create a function to be called that will basically reduce the number of coins one individual person has. ensuring they have enough credit available.

(im aware there are other more individual ways of doing this as per shop/pricing but it doesnt particularly fit with the bigger scheme of things to what im trying to achieve hence a seperate function for just reducing the coin count by 50 is what im after.

 

function purchasebox()

{
list($coin1) = mysql_fetch_row(mysql_query("select coin from users where id='$_SESSION[user_id]'"));
if ($coin1> '49') 
{
$newcoin = $coin1 - '50';	   

mysql_fetch_row(mysql_query("UPDATE sdaccount.users SET coin ='$newcoin' WHERE id='$_SESSION[user_id]'"));


echo "Successfully bought!";

	   } 

else {
		   echo "Not enough coins";

		  }

}

 

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\supreme\dbc.php on line 172

Box successfully bought!

 

 mysql_fetch_row(mysql_query("UPDATE sdaccount.users SET coin ='$newcoin' WHERE id='$_SESSION[user_id]'"));

is line 172

 

Thanks for any help, im sure its so stupidly obvious what ive done lol, im just having a very long blonde moment >.<!

 

Regards.

 

Edit: One thing to be noted, it is actually working as far as I can see, It is updating the correct person's coin, and follows the rule of more than 50. and will subtract 50 if they have sufficient coin. So it appears to work, its just not clear why its giving this error.

Think i fixed this, i did a little more reading, i was having a severe blonde moment, apparently i was mis-using the mysql_query in the second query line (172) I was doing another fetch which is supposed to return a resource, where as for an update i need to be requesting boolean.

 

>feels stupid for no realizing how sloppy that coding was grmbl<

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.