Jump to content
MakeWebGames

what am I missing here?


Recommended Posts

I'm working here on 1 item. A rifle, itemid 297 itmtype 15

 

$q=$db->query("SELECT `inv_userid`, `inv_itemid`, `itmtype` FROM `inventory` AS iv INNER JOIN `items` AS i ON iv.inv_itemid=i.itmid WHERE iv.inv_userid={$ir['userid']} AND i.itmid={$_GET['ID']}");
$r=$db->fetch_row($q);
if($r['itmtype'] !== 15)
{
echo "This item is not a Gun!<br />

<a href='inventory.php' class='button'>Exit</a>";
$h->endpage();
exit;
}  

 

But it keeps giving me that ^ portion of the script.

Also tried

 

if($db->num_rows($q)==0)
Link to comment
Share on other sites

I'm working here on 1 item. A rifle, itemid 297 itmtype 15

 

$q=$db->query("SELECT `inv_userid`, `inv_itemid`, `itmtype` FROM `inventory` AS iv INNER JOIN `items` AS i ON iv.inv_itemid=i.itmid WHERE iv.inv_userid={$ir['userid']} AND i.itmid={$_GET['ID']}");
$r=$db->fetch_row($q);
if($r['itmtype'] !== 15)
{
echo "This item is not a Gun!<br />

<a href='inventory.php' class='button'>Exit</a>";
$h->endpage();
exit;
} 

 

But it keeps giving me that ^ portion of the script.

Also tried

 

if($db->num_rows($q)==0)

instead of using the !== which is identical use the == (equals)

so basicly try this

$q = $db->query("SELECT `inv_userid`,`inv_itemid`,`itmtype` FROM `inventory` AS iv INNER JOIN `items` AS i ON `iv`.`inv_itemid` = `i`.`itmid` WHERE `iv`.`inv_userid` = {$ir['userid']} AND `i`.`itmid` = ".$_GET['ID']);

// you are missing a row to check if the item is even real just assuming it is

if(!$db->num_rows($q)) {

$db->free_resources($q);

echo "Invalid Item.";

$h->endpage();

exit;

}

$r = $db->fetch_row($q);

if(in_array($r['itmtype'],array(15)))

{

echo "This item is not a Gun!<br /> <a href='inventory.php' class='button'>Exit</a>";

$h->endpage();

exit;

}

if that fails try this

$q = $db->query("SELECT `inv_userid`,`inv_itemid`,`itmtype` FROM `inventory` AS iv INNER JOIN `items` AS i ON `iv`.`inv_itemid` = `i`.`itmid` WHERE `iv`.`inv_userid` = {$ir['userid']} AND `iv`.`itmid` = ".$_GET['ID']);

// you are missing a row to check if the item is even real just assuming it is

if(!$db->num_rows($q)) {

$db->free_resources($q);

echo "Invalid Item.";

$h->endpage();

exit;

}

$r = $db->fetch_row($q);

if(in_array($r['itmtype'],array(15)))

{

echo "This item is not a Gun!<br /> <a href='inventory.php' class='button'>Exit</a>";

$h->endpage();

exit;

}

 

 

 

so basicly with the array option you need to add a , followed by another item type you wish to block

 

 

Link to comment
Share on other sites

This is assuming you've sanitized the getdata

$q = $db->query('SELECT `inv_userid`, `inv_itemid`, `itmname`, `itmtype`
FROM `inventory`
INNER JOIN `items` ON `inv_itemid` = `itmid`
WHERE `inv_userid` = '.$ir['userid'].' AND `itmid` = '.$_GET['ID']);
if(!$db->num_rows($q)) {
   echo 'Either that item doesn\'t exist or it\'s not yours';
   exit($h->endpage());
}
$r = $db->fetch_row($q);
if($r['itmtype'] != 15) {
   echo 'You can\'t buy ammo for the '.$r['itmname'];
   exit($h->endpage());
}
Edited by Magictallguy
Link to comment
Share on other sites

I will try that. But I don't want to block the itemtype I only want the item type gun (15) to allow ammo purchases.

i know you only wanted to block gun but say in future you changed your mind the array was there blocking the gun already if you wanted to block a special item then you could addapt the code easy without adding || $r['itemtype'] == xx etc if that makes any sense to you but if not [uSER=53425]Magictallguy[/uSER] did it for you :P even tho it does the same thing

Link to comment
Share on other sites

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...