SHAD Posted February 22, 2010 Share Posted February 22, 2010 OK i have a problem with my inventry,when i buy two of the same items at different times,it does not stack them up. How can it be prevented,please help. <?php include "globals.php"; if(isset($_SESSION['timer']) && time() < $_SESSION['timer'] + 10) { $time_left = ((time() - $_SESSION['timer']) - 10); echo sprintf("You cannot buy yet, please wait for %s more second%s", str_replace('-', '', $time_left), ($time_left == -1) ? '' : 's'); $h->endpage(); exit; } if(isset($_SESSION['timer']) && time() > $_SESSION['timer'] + 9) { unset($_SESSION['timer']); } $_SESSION['timer'] = time(); if($ir[hospital]>0) die("You are in the hospital for {$ir[hospital]} minutes."); if($ir[jail]>0) die("You are in jail for {$ir[jail]} minutes."); $_GET['ID']= abs((int) $_GET['ID']); $_POST['qty']= abs((int) $_POST['qty']); if(!$_GET['ID'] || !$_POST['qty']) { print "Invalid use of file"; } else if($_POST['qty'] <= 0) { print "You have been added to the delete list for trying to cheat the game."; } else { $q=mysql_query("SELECT * FROM items WHERE itmid={$_GET['ID']}",$c); if(mysql_num_rows($q) == 0) { print "Invalid item ID"; } else { $itemd=mysql_fetch_array($q); if($ir['money'] < $itemd['itmbuyprice']*$_POST['qty']) { print "You don't have enough money to buy this item!"; $h->endpage(); exit; } if($itemd['itmbuyable'] == 0) { print "This item can't be bought!"; $h->endpage(); exit; } $price=($itemd['itmbuyprice']*$_POST['qty']); mysql_query("INSERT INTO inventory VALUES('',{$_GET['ID']},$userid,{$_POST['qty']},0);",$c); mysql_query("UPDATE users SET money=money-$price WHERE userid=$userid",$c); mysql_query("INSERT INTO itembuylogs VALUES ('', $userid, {$_GET['ID']}, $price, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$price}')", $c); print "You bought {$_POST['qty']} {$itemd['itmname']}(s) for \$$price"; } } $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
seanybob Posted February 22, 2010 Share Posted February 22, 2010 The problem, then, is not with your inventory but with your itembuy script. Post that up here and I'll help you out. Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 22, 2010 Share Posted February 22, 2010 Item_Add Hello, maybe i could direct your attention to a function in global_func.php item_add($user, $itemid, $qty); so where you have mysql_query("INSERT INTO inventory VALUES('',{$_GET['ID']},$userid,{$_POST['qty']},0);",$c); mysql_query("UPDATE users SET money=money-$price WHERE userid=$userid",$c); mysql_query("INSERT INTO itembuylogs VALUES ('', $userid, {$_GET['ID']}, $price, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$price}')", $c); you could add item_add($userid, $_GET['ID'], $_POST['qty']); $db->query("UPDATE `users` SET `money` = `money` - $price WHERE `userid` = $userid"); $db->query("INSERT INTO `itembuylogs` VALUES ('', $userid, {$_GET['ID']}, $price, {$_POST['qty']}, unix_timestamp(), '{$ir['username']} bought {$_POST['qty']} {$itemd['itmname']}(s) for {$price}')"); Quote Link to comment Share on other sites More sharing options...
seanybob Posted February 22, 2010 Share Posted February 22, 2010 Doh. Crimgame, after seeing your response I actually went up and checked the code he posted. I assumed it had just been his inventory script, but now see it did have his itembuy code... Glad you're not as lazy as me. Ya SHAD, crimgame nailed your problem. The function he pointed out combines like items when it adds them, getting rid of your problem. Quote Link to comment Share on other sites More sharing options...
SHAD Posted February 22, 2010 Author Share Posted February 22, 2010 uhh,thank god for this fix,Thank you very much crimegame :thumbup: Quote Link to comment Share on other sites More sharing options...
Zero-Affect Posted February 22, 2010 Share Posted February 22, 2010 OMG i got something right! *victory dance*. @ Shad - Your welcome mate, any other issues just ask. @ seanybob - Lazy bugger lol 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.