modernmafiia Posted May 26, 2012 Posted May 26, 2012 Ok i have taken a bit of the coding out from the shop so it is a global shop and doesnt have to appear in certain locations, I also added a new colum to items tables which is for location i have set my item with a location but having some troubled adding the restriction to itembuy.php to pickout the colum from items called LOC which = to locations it displays the error code even if im in the right location. <?php include_once (DIRNAME(__FILE__) . '/globals.php'); $_GET['ID'] = ( isset($_GET['ID'])&&is_numeric($_GET['ID']) )?abs(intval($_GET['ID'])):''; $_POST['qty'] = ( isset($_POST['qty'])&&is_numeric($_POST['qty']) )?abs(intval($_POST['qty'])):''; if ( empty($_GET['ID']) OR empty($_POST['qty']) ) { echo 'Invalid use of file'; } else { $q = $db->query("SELECT `itmbuyprice`,`itmname`,`itmbuyable` FROM `items` WHERE `itmid` = {$_GET['ID']}"); if ( $db->num_rows($q) == 0 ) { echo 'Invalid item ID'; } else { $itemd = $db->fetch_row($q); if ( $ir['money'] < ($itemd['itmbuyprice'] * $_POST['qty']) ) { echo 'You don\'t have enough money to buy '.$_POST['qty'].' '.$itemd['itmname'].'!<br /><br />> <a href="index.php">Go Home</a>'; die($h->endpage()); } if ( $itemd['itmbuyable'] == 0 ) { echo 'This item can\'t be bought!<br /><br />> <a href="index.php">Go Home</a>'; die($h->endpage()); } $erq=$db->query("SELECT * FROM items"); while($rr=$db->fetch_row($erq)) { if($rr[loc] == $ir['location']) { echo "You cannot purchase this item from another city"; die($h->endpage()); } } $price = ($itemd['itmbuyprice'] * $_POST['qty']); 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}')"); echo 'You bought '.$_POST['qty'].' <img src="'.$itemd['itmname'].'"> '.(($_POST['qty'] > 1) ? 's' : '').' for '.money_formatter($price).'<br /><br />> <a href="inventory.php">View your Bag</a>'; } } $h->endpage(); ?> Quote
sniko Posted May 26, 2012 Posted May 26, 2012 Edit the query, line 11. $q = $db->query("SELECT `itmbuyprice`,`itmname`,`itmbuyable` FROM `items` WHERE `itmid` = {$_GET['ID']} AND ( `LOC` = {$ir['location']} OR `LOC` = 0)"); If I read what you requested correctly, this will only return the details of the item if; The item ID is valid You're in the correct location Or the item location is set to 0, which I assume was default :? Quote
modernmafiia Posted May 26, 2012 Author Posted May 26, 2012 I have replaced did not work i was in same location as the item said invalid ID said it with all item in different locations i tried it Quote
rulerofzu Posted May 26, 2012 Posted May 26, 2012 itmid = {$_GET['ID']} && `'LOC` = {$ir['location']} should be all you require in the query. 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.