Page 1 of 1

Can't figure out this query problem..

Posted: Sat Feb 04, 2012 7:53 pm
by MikeD
Well thought I would be finished with my equipment in no time, but I have run into an extremely frustrating problem.

When I equip an item, it unequips everything else, but leaves any equipped attachments alone (Which it shouldn't if it's unequipping items).

I've spent over 2 hours looking at this trying to find a problem, but I can't find one :/

I believe the problem is on this line

Code: Select all

$updateeq ="UPDATE `playeritems` SET `equip`='0' WHERE `iclass`='Helmet' AND `cid`='$cid';";
(And yes, iclass names are Capitalized in the DB)

Code: Select all

if (isset($_POST['equip']))
  {
    $equipid=$_POST['equipid']; //From form.
    
    $check="SELECT `pid`,`cid` FROM `playeritems` WHERE `eqid`='$equipid'";
    $check2=mysqli_query($db,$check) or die(mysqli_error($db));
    $check3=mysqli_fetch_array($check2);
   
if ($cid == $check3['cid'] AND $pid == $check3['pid'])//Make sure the item belongs to player
      {
        //Query to get ID of the type equipped already so we can unequip all of it's attachments.
        $id="SELECT `eqid` FROM `playeritems` WHERE `cid`='$cid' AND `equip`='1' AND `iclass`='Helmet' LIMIT 1"; 
        $id2=mysqli_query($db,$id) or die(mysqli_error($db));
        $id3=mysqli_fetch_array($id2);
        $eid=$id3['eqid']; 
        
        $updateeq ="UPDATE `playeritems` SET `equip`='0' WHERE `iclass`='Helmet' AND `cid`='$cid';";
        $updateeq .="UPDATE `playeritems` SET `equip`='0' WHERE `attachid`='$eid';";
        $updateeq .="UPDATE `playeritems` SET `equip`='1' WHERE `eqid`='$equipid';";
        $updateeq .="UPDATE `playeritems` SET `equip`='1' WHERE `attachid`='$equipid'";
        mysqli_multi_query ($db, $updateeq) or die(mysqli_error($db));
        mysqli_next_result($db);
        mysqli_next_result($db);
        mysqli_next_result($db);
      }
    else
      {
        echo "You're trying to equip something that's not yours!";
        exit;
      }
  }

Re: Can't figure out this query problem..

Posted: Sat Feb 04, 2012 8:53 pm
by Ark
what does mysqli_error() says about this?

Re: Can't figure out this query problem..

Posted: Sat Feb 04, 2012 9:23 pm
by MikeD
Ark wrote:what does mysqli_error() says about this?
No error :(

Re: Can't figure out this query problem..

Posted: Sat Feb 04, 2012 9:50 pm
by MikeD
Figured it out...

By default, every item in table `playeritems` has an attachid set to 0, so if there was nothing equipped when you're trying to equip something, the $eid would = 0.

Took me too long to realize this..All fixed now.