Seker Posted May 18, 2012 Posted May 18, 2012 I found an item_give function posted here by AlabamaHit a while back. Now, using it in my streets mod doesn't give me a problem. However, when I try to replace the SQL query in itembuy.php, it doesn't update the inventory, and I get this: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/*******/public_html/global_func.php on line 348 Here's the item_add function as it is in global_func.php: function item_give($userid, $itemid, $qty, $notid=0) { if($notid > 0) { $q=mysql_query("SELECT * FROM inventory WHERE inv_userid={$userid} and inv_itemid={$itemid} AND inv_id != {$notid}"); } else { $q=mysql_query("SELECT * FROM inventory WHERE inv_userid={$userid} and inv_itemid={$itemid}"); } if(mysql_num_rows($q) > 0) { $r=mysql_fetch_array($q); mysql_query("UPDATE inventory SET inv_qty=inv_qty+{$qty} WHERE inv_id={$r['inv_id']}"); } else { mysql_query("INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) VALUES ({$itemid}, {$userid}, {$qty})"); } } What I have in itembuy.php: item_give($_NULL,$_GET['ID'],$userid,$_POST['qty']); Any ideas what I'm doing wrong? And, it's worth mentioning, when I add the { } around each of the values, it throws an "unexpected {" error. Quote
rulerofzu Posted May 18, 2012 Posted May 18, 2012 You have failed to understand the function in your itembuy it will expect parameters passed to it in order So question is where did you get $_NULL from? item_give($userid,$_GET['id'],$_POST['qty']) Also have you secured those GET and POST values if not then your players will have a lot of fun Quote
Seker Posted May 18, 2012 Author Posted May 18, 2012 Yeah, actually, I took the $_NULL out and it stopped the SQL warning. However, it's still not updating the inventory. As far as security... That's my last planned step. I don't see any use in going through and securing every file while I'm still changing just about everything's layout/content on a daily basis. Not a problem until the game goes live. Quote
rulerofzu Posted May 18, 2012 Posted May 18, 2012 Even with the null taken out your values are in the wrong order For example using the code you have there Itemid : 1500 Qty: 2 Userid: 1 Your code will attempt to do the following userid: 1500, itemid: 1, qty: 2 Quote
Seker Posted May 18, 2012 Author Posted May 18, 2012 Even with the null taken out your values are in the wrong order For example using the code you have there Itemid : 1500 Qty: 2 Userid: 1 Your code will attempt to do the following userid: 1500, itemid: 1, qty: 2 "INSERT INTO inventory (inv_itemid, inv_userid, inv_qty) item_give($_GET['ID'],$userid,$_POST['qty']); That doesn't match up? Quote
Djkanna Posted May 18, 2012 Posted May 18, 2012 function item_give($userid, $itemid, $qty, $notid=0) { No it doesn't. :) Quote
Seker Posted May 18, 2012 Author Posted May 18, 2012 function item_give($userid, $itemid, $qty, $notid=0) { No it doesn't. :) Ah well, I'll try that order. I just thought, surely, it would go by the INSERT. Shows my freshness to the world of PHP, I suppose. Quote
Paul Evans Posted May 18, 2012 Posted May 18, 2012 item_give($userid,$_GET['ID'],$_POST['qty']); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.