Jump to content
MakeWebGames

Recommended Posts

Posted

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();
?>
Posted

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 :?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...