newttster Posted January 4, 2012 Share Posted January 4, 2012 Can anyone tell me why I am getting this error? Obviously I am not defining something correctly, but I can't figure out what it is. The storagebox table has sbox_id, sbox_itemid, sbox_userid, sbox_qty. This is the error that I am getting. QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= `sbox_itemid` AND `sbox_userid` = '1'' at line 1 Query was UPDATE `storagebox` SET `sbox_qty` = `sbox_qty` + 1000 WHERE = `sbox_itemid` AND `sbox_userid` = '1' This is the code that I am working with. <?php include "globals.php"; switch ($_GET['action']) { case 'gotransfer': go_transfer(); break; case 'transferdone': transfer_done(); break; default: index(); break; } //~~~~~~~~~~~~~~~~~~~~~~~~ function index() { global $db,$ir,$c,$userid,$h; $item=mysql_query("SELECT `inv_qty` FROM `inventory` WHERE `inv_itemid`='564' AND `inv_userid`='$userid'"); $item1=mysql_fetch_assoc($item); echo "<h2><u>Welcome to the transfer center</u></h2>"; echo "<table bordercolor=red border=1><td><h4>You currently have {$item1['inv_qty']} Silver Flakes to transfer.</h4><br /> <form action='transfer.php?action=gotransfer' method='post'> <input type='hidden' size='5'name='transfergem' /> <center><input type='submit' value='Transfer' /></center></form></td></table> "; $h->endpage(); exit; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function go_transfer() { global $db,$ir,$c,$userid,$h; $item=mysql_query("SELECT `inv_qty` FROM `inventory` WHERE `inv_itemid`='564' AND `inv_userid`='$userid'"); $item1=mysql_fetch_assoc($item); if($_POST['transfergem'] > $item1['inv_qty']) { echo "You are trying to transfer more than you have.<hr /> <a href='transfer.php'>Back</a>"; } else { echo"You've chosen to transfer {$item1['inv_qty']}.<br /> <form action='transfer.php?action=transferdone' method='post'> How many do you want to transfer? <input type='text' size='5' name='transfergem' value='' /> <input type='submit' value='Transfer Item' /></form>"; } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function transfer_done() { global $db,$ir,$c,$userid,$h; $item=mysql_query("SELECT `inv_qty` FROM `inventory` WHERE `inv_itemid`='564' AND `inv_userid`='$userid'"); $item1=mysql_fetch_assoc($item); $inc=$item1['inv_qty']-$_POST['transfergem']; $tabs=$_POST['transfergem']; $gain=$_POST['transfergem']; $db->query("UPDATE `storagebox` SET `sbox_qty` = `sbox_qty` + ". $gain ." WHERE {$item1['inv_itemid']} = `sbox_itemid` AND `sbox_userid` = '$userid'"); item_remove($userid,564,$tabs); echo "Congratulations!<br /> You have transferred {$tabs} to your Storage box.<br /> You now have {$inc} left in your inventory.<br /> <a href='transfer.php'>Transfer more</a><br /> <a href='explore.php'>Back to town</a>"; } $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted January 4, 2012 Share Posted January 4, 2012 Yep see what you have $item=mysql_query("SELECT `inv_qty` FROM `inventory` WHERE `inv_itemid`='564' AND `inv_userid`='$userid'"); $item1=mysql_fetch_assoc($item); $inc=$item1['inv_qty']-$_POST['transfergem']; $tabs=$_POST['transfergem']; $gain=$_POST['transfergem']; $db->query("UPDATE `storagebox` SET `sbox_qty` = `sbox_qty` + ". $gain ." WHERE {$item1['inv_itemid']} = `sbox_itemid` AND `sbox_userid` = '$userid'"); Need to add inv_itemid to your query selecting/ To: $item=mysql_query("SELECT `inv_qty`,`inv_itemid` FROM `inventory` WHERE `inv_itemid`='564' AND `inv_userid`='$userid'"); Quote Link to comment Share on other sites More sharing options...
newttster Posted March 10, 2012 Author Share Posted March 10, 2012 Sorry ... foget to get back to this one. Thanks lucky ... that and a few other little tweeks is just what I needed to get it working. So thanks again. Quote Link to comment Share on other sites More sharing options...
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.