Jump to content

Long topic, query is not working


TeddyKiller

Recommended Posts

I don't know how to explain this. Here goes.

When a user has no items, and they purchase an item it works wonderfully, also purchasing multiples of the same item works wonderfully.

When I try purchase a different item when I already have one, but this is different.. It'll echo out "error" but doesn't complete $query2, infact it just ignores it. I want users to be able to purchase multiple items.

Thats the only problem, if $query2 would work more than once when a user has an item it'd be fine.

 

All items have a different ID, so it basically checks the database, and if there is no rows for that user with item id then to insert it. Just doesn't work. No errors get displayed either.

It just simply, ignores it.

 

You'll be looking in -case "buy"

though like I say.. it will echo out "error" which I put in to test if It got that far, just will not do the query.

 

Heres the page code.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

include("lib.php");
include("tmpconfig.php");
define("PAGENAME", "Shop");
$player = check_user($secret_key, $db);

switch($_GET['act'])
{
    case "buy":
        if (!$_GET['id']) //No item ID
        {
            header("Location: shop.php");
            break;
        }
        
        //Select the item from the database
        $query = $db->execute("select `id`, `name`, `price`, `type`, `descript` from `items` where `id`=?", array($_GET['id']));
        
        //Invalid item (it doesn't exist)
        if ($query->recordcount() == 0)
        {
            header("Location: shop.php");
            break;
        }
        
        $item = $query->fetchrow();
        if ($item['price'] > $player->gold)
        {
            echo "<b>Shop Keeper:</b><br />\n";
            echo "<i>Sorry, but you cannot afford this!</i><br /><br />\n";
            echo "<a href=\"inventory.php\">Return to inventory</a> | <a href=\"shop.php\">Return to shop</a>";
            break;
        }

        $q1 = $db->execute("select * from `inventory` where `player`=? and item_id=?", array($player->id,$_GET['id']));
        if($q1->recordcount() == 0)
        {
        echo 'error<br />';
        $query2 = mysql_query("insert into `inventory` (player, quantity, status, item_id, type) values ('".$player->id."','0','unequipped','".$_GET['id']."','".$item['type']."')");
        //$query2 = $db->autoexecute('inventory', $insert, 'INSERT'); 
        }

        $query1 = $db->execute("update `users` set `gold`=? where `id`=?", array($player->gold - $item['price'], $player->id));
        $insert['player'] = $player->id;
        $insert['item_id'] = $item['id'];
        
        
        $q = $db->execute("select * from `inventory` where `player`='".$insert['player']."'");
        $row = $q->fetchrow();
        
        $query = $db->execute("update `inventory` set `quantity`=? where `item_id`='".$item['id']."' and `player`='".$insert['player']."'", array($row['quantity'] + 1));

        if ($query && $query1) //If successful
        {
            $player = check_user($secret_key, $db); //Get new user stats
            
            echo "<b>Shop Keeper:</b><br />\n";
            
            if ($query2){echo "<strong>You purchased a new item!</strong><br />";}
            
            echo "<i>Thank you, enjoy your new <b>" . $item['name'] . "</b>!</i><br /><br />\n";

            $q1 = $db->execute("select * from `inventory` where `item_id`='".$_GET['id']."' and `player`='".$insert['player']."'");
            $row1 = $q1->fetchrow();

            echo "<i>You now have " . $row1['quantity'] . " <b>" . $item['name'] . "(s)</b>!</i><br /><br />\n";
            echo "<a href=\"inventory.php\">Return to inventory</a> | <a href=\"shop.php\">Return to shop</a>";
            break;
        }
        else
        {
            //Error logging here
        }
        
        break;
        
    case "sell":
        if (!$_GET['id']) //No item ID
        {
            header("Location: shop.php");
            break;
        }
        
        //Select the item from the database
        $inventitemid = $_GET['id'];
        $query = $db->execute("select * from `inventory` where inventory.item_id='".$inventitemid."' and inventory.player=?", array($player->id));
        //Either item doesn't exist, or item doesn't belong to user
        if($query->recordcount() == 0){ echo "Sorry, that item does not exist!"; break;}
        $query = $db->execute("select items.name, items.price from `items` where items.id=?", array($_GET['id']));
        
        //Either item doesn't exist, or item doesn't belong to user
        if ($query->recordcount() == 0)
        {
            echo "Sorry, that item does not exist!";
            break;
        }
        
        $sell = $query->fetchrow(); //Get item info
        
        //Check to make sure clicking Sell wasn't an accident
        if (!$_POST['sure'])
        {
            echo "Are you sure you want to sell your <b>" . $sell['name'] . "</b> for <b>" . floor($sell['price']/2) . "</b> gold?<br /><br />\n";
            echo "<form method=\"post\" action=\"shop.php?act=sell&id=" . $inventitemid . "\">\n";
            echo "<input type=\"submit\" name=\"sure\" value=\"Yes, I am sure!\" />\n";
            echo "</form>\n";
            break;
        }
        
        //Delete item from database, add gold to player's account
        $query = $db->execute("delete from `inventory` where `item_id`=? and `player`=?", array($inventitemid, $player->id));
        $query = $db->execute("update `users` set `gold`=? where `id`=?", array($player->gold + floor($sell['price']/2), $player->id));
        
        $player = check_user($secret_key, $db); //Get updated user info
        
        echo "You have sold your <b>" . $sell['name'] . "</b> for <b>" . floor($sell['price']/2) . "</b> gold.<br /><br />\n";
        echo "<a href=\"inventory.php\">Return to inventory</a> | <a href=\"shop.php\">Return to shop</a>";
        break;
    
    case "weapon":
        //Check in case somebody entered 0
        $_GET['fromprice'] = ($_GET['fromprice'] == 0)?"":$_GET['fromprice'];
        $_GET['toprice'] = ($_GET['toprice'] == 0)?"":$_GET['toprice'];

        
        //Construct query
        $query = "select `id`, `name`, `slot`, `price`, `type`, `bonus`, `target`, `attr`, `effect`, `value`, `descript` from `items` where ";
        $query .= ($_GET['name'] != "")?"`name` LIKE  ? and ":"";
        $query .= ($_GET['fromprice'] != "")?"`price` >= ? and ":"";
        $query .= ($_GET['toprice'] != "")?"`price` <= ? and ":"";        
        $query .= "`type`='weapon' order by `price` asc";
        
        //Construct values array for adoDB
        $values = array();
        if ($_GET['name'] != "")
        {
            array_push($values, "%".trim($_GET['name'])."%");
        }
        if ($_GET['fromprice'])
        {
            array_push($values, intval($_GET['fromprice']));
        }
        if ($_GET['toprice'])
        {
            array_push($values, intval($_GET['toprice']));
        }
        
        $query = $db->execute($query, $values); //Search!
        
        $q = $db->execute("select * from `users` where `id`=?", array($player->id));
        $r = $q->fetchrow();
        if($r['gender'] == 'male'){$sirmad = 'sir';}else{$sirmad = 'madam';}
        echo "<fieldset>";
        echo "<legend><b>Shop Keeper:</b></legend>\n";
        echo "<i>What would you like to see, ".$sirmad."?</i><br /><br />\n";
        echo "<form method=\"get\" action=\"shop.php\">\n";
        echo "<table width=\"100%\">\n";
        echo "<tr>\n<td width=\"40%\">Name:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"name\" value=\"" . stripslashes($_GET['name']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Price:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"fromprice\" size=\"4\" value=\"" . stripslashes($_GET['fromprice']) . "\" /> to <input type=\"text\" name=\"toprice\" size=\"4\" value=\"" . stripslashes($_GET['toprice']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Type:</td>\n";
        echo "<td width=\"60%\"><select name=\"act\" size=\"2\">\n";
        echo "<option value=\"weapon\" selected=\"selected\">Weapons</option>\n";
        echo "<option value=\"head\">Headgear</option>\n";
        echo "<option value=\"shield\">Shields</option>\n";
        echo "<option value=\"neck\">Neck</option>\n";
        echo "<option value=\"shoulders\">Shoulders</option>\n";
        echo "<option value=\"body\">Body</option>\n";
        echo "<option value=\"arm\">Arms</option>\n";
        echo "<option value=\"wrists\">Wrist</option>\n";
        echo "<option value=\"hands\">Hands</option>\n";
        echo "<option value=\"finger\">Fingers</option>\n";
        echo "<option value=\"legs\">Legs</option>\n";
        echo "<option value=\"feet\">Feet</option>\n";
        echo "<option value=\"pet\">Pets</option>\n";
        echo "</select></td>\n</tr>\n";
        echo "<tr>\n<td></td>";
        echo "<td><input type=\"submit\" value=\"Submit\" /></td>\n</tr>";
        echo "</table>";
        echo "</form>\n";
        echo "</fieldset>";
        echo "<br /><br />";
        echo "<b>Shop Keeper:</b><br />\n";
        echo "<i>Here's our collection:</i><br /><br />\n";
        
        if ($query->recordcount() == 0)
        {
            echo "No items found! Try changing your search criteria.";
        }
        else
        {
            while ($item = $query->fetchrow())
            {
                echo "<fieldset>\n";
                echo "<legend><b>" . $item['name'] . "</b></legend>\n";
                echo "<table width=\"100%\">\n";
                echo "<tr><td width=\"85%\">";
                echo $item['descript'] . "\n<br />";
                echo "</td><td width=\"15%\">";
                echo "<b>Price:</b> " . $item['price'] . "<br />";
                echo "<a href=\"shop.php?act=buy&id=" . $item['id'] . "\">Buy</a><br />";
                echo "</td></tr>\n";
                echo "</table>";
                echo "</fieldset>\n<br />";
            }
        }
        break;
    
    case "shield":
        //Check in case somebody entered 0
        $_GET['fromprice'] = ($_GET['fromprice'] == 0)?"":$_GET['fromprice'];
        $_GET['toprice'] = ($_GET['toprice'] == 0)?"":$_GET['toprice'];
        
        //Construct query
        $query = "select `id`, `name`, `slot`, `price`, `type`, `bonus`, `target`, `attr`, `effect`, `value`, `descript` from `items` where ";
        $query .= ($_GET['name'] != "")?"`name` LIKE  ? and ":"";
        $query .= ($_GET['fromprice'] != "")?"`price` >= ? and ":"";
        $query .= ($_GET['toprice'] != "")?"`price` <= ? and ":"";        
        $query .= "`slot`='shield' order by `price` asc";
        
        //Construct values array for adoDB
        $values = array();
        if ($_GET['name'] != "")
        {
            array_push($values, "%".trim($_GET['name'])."%");
        }
        if ($_GET['fromprice'])
        {
            array_push($values, intval($_GET['fromprice']));
        }
        if ($_GET['toprice'])
        {
            array_push($values, intval($_GET['toprice']));
        }
        
        $query = $db->execute($query, $values); //Search!
        
        $q = $db->execute("select * from `users` where `id`=?", array($player->id));
        $r = $q->fetchrow();        
        if($r['gender'] == 'male'){$sirmad = 'sir';}else{$sirmad = 'madam';}    
        echo "<fieldset>";
        echo "<legend><b>Shop Keeper:</b></legend>\n";
        echo "<i>What would you like to see, ".$sirmad."?</i><br /><br />\n";
        echo "<form method=\"get\" action=\"shop.php\">\n";
        echo "<table width=\"100%\">\n";
        echo "<tr>\n<td width=\"40%\">Name:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"name\" value=\"" . stripslashes($_GET['name']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Price:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"fromprice\" size=\"4\" value=\"" . stripslashes($_GET['fromprice']) . "\" /> to <input type=\"text\" name=\"toprice\" size=\"4\" value=\"" . stripslashes($_GET['toprice']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Type:</td>\n";
        echo "<td width=\"60%\"><select name=\"act\" size=\"2\">\n";
        echo "<option value=\"weapon\">Weapons</option>\n";
        echo "<option value=\"head\">Headgear</option>\n";
        echo "<option value=\"shield\"  selected=\"selected\">Shields</option>\n";
        echo "<option value=\"neck\">Neck</option>\n";
        echo "<option value=\"shoulders\">Shoulders</option>\n";
        echo "<option value=\"body\">Body</option>\n";
        echo "<option value=\"arm\">Arms</option>\n";
        echo "<option value=\"wrists\">Wrist</option>\n";
        echo "<option value=\"hands\">Hands</option>\n";
        echo "<option value=\"finger\">Fingers</option>\n";
        echo "<option value=\"legs\">Legs</option>\n";
        echo "<option value=\"feet\">Feet</option>\n";
        echo "<option value=\"pet\">Pets</option>\n";
        echo "</select></td>\n</tr>\n";
        echo "<tr>\n<td></td>";
        echo "<td><input type=\"submit\" value=\"Submit\" /></td>\n</tr>";
        echo "</table>";
        echo "</form>\n";
        echo "</fieldset>";
        echo "<br /><br />";
        echo "<b>Shop Keeper:</b><br />\n";
        echo "<i>Here's our collection:</i><br /><br />\n";
        
        if ($query->recordcount() == 0)
        {
            echo "No items found! Try changing your search criteria.";
        }
        else
        {
            while ($item = $query->fetchrow())
            {
                echo "<fieldset>\n";
                echo "<legend><b>" . $item['name'] . "</b></legend>\n";
                echo "<table width=\"100%\">\n";
                echo "<tr><td width=\"85%\">";
                echo $item['descript'] . "\n<br />";
                echo "</td><td width=\"15%\">";
                echo "<b>Price:</b> " . $item['price'] . "<br />";
                echo "<a href=\"shop.php?act=buy&id=" . $item['id'] . "\">Buy</a><br />";
                echo "</td></tr>\n";
                echo "</table>";
                echo "</fieldset>\n<br />";
            }
        }
        
        break;
    
    case "head":
        //Check in case somebody entered 0
        $_GET['fromprice'] = ($_GET['fromprice'] == 0)?"":$_GET['fromprice'];
        $_GET['toprice'] = ($_GET['toprice'] == 0)?"":$_GET['toprice'];
        
        //Construct query
        $query = "select `id`, `name`, `slot`, `price`, `type`, `bonus`, `target`, `attr`, `effect`, `value`, `descript` from `items` where ";
        $query .= ($_GET['name'] != "")?"`name` LIKE  ? and ":"";
        $query .= ($_GET['fromprice'] != "")?"`price` >= ? and ":"";
        $query .= ($_GET['toprice'] != "")?"`price` <= ? and ":"";        
        $query .= "`slot`='head' order by `price` asc";
        
        //Construct values array for adoDB
        $values = array();
        if ($_GET['name'] != "")
        {
            array_push($values, "%".trim($_GET['name'])."%");
        }
        if ($_GET['fromprice'])
        {
            array_push($values, intval($_GET['fromprice']));
        }
        if ($_GET['toprice'])
        {
            array_push($values, intval($_GET['toprice']));
        }
        
        $query = $db->execute($query, $values); //Search!
        
        $q = $db->execute("select * from `users` where `id`=?", array($player->id));
        $r = $q->fetchrow();        
        if($r['gender'] == 'male'){$sirmad = 'sir';}else{$sirmad = 'madam';}    
        echo "<fieldset>";
        echo "<legend><b>Shop Keeper:</b></legend>\n";
        echo "<i>What would you like to see, ".$sirmad."?</i><br /><br />\n";
        echo "<form method=\"get\" action=\"shop.php\">\n";
        echo "<table width=\"100%\">\n";
        echo "<tr>\n<td width=\"40%\">Name:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"name\" value=\"" . stripslashes($_GET['name']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Price:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"fromprice\" size=\"4\" value=\"" . stripslashes($_GET['fromprice']) . "\" /> to <input type=\"text\" name=\"toprice\" size=\"4\" value=\"" . stripslashes($_GET['toprice']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Type:</td>\n";
        echo "<td width=\"60%\"><select name=\"act\" size=\"2\">\n";
        echo "<option value=\"weapon\">Weapons</option>\n";
        echo "<option value=\"head\" selected=\"selected\">Headgear</option>\n";
        echo "<option value=\"shield\">Shields</option>\n";
        echo "<option value=\"neck\">Neck</option>\n";
        echo "<option value=\"shoulders\">Shoulders</option>\n";
        echo "<option value=\"body\">Body</option>\n";
        echo "<option value=\"arm\">Arms</option>\n";
        echo "<option value=\"wrists\">Wrist</option>\n";
        echo "<option value=\"hands\">Hands</option>\n";
        echo "<option value=\"finger\">Fingers</option>\n";
        echo "<option value=\"legs\">Legs</option>\n";
        echo "<option value=\"feet\">Feet</option>\n";
        echo "<option value=\"pet\">Pets</option>\n";
        echo "</select></td>\n</tr>\n";
        echo "<tr>\n<td></td>";
        echo "<td><input type=\"submit\" value=\"Submit\" /></td>\n</tr>";
        echo "</table>";
        echo "</form>\n";
        echo "</fieldset>";
        echo "<br /><br />";
        echo "<b>Shop Keeper:</b><br />\n";
        echo "<i>Here's our collection:</i><br /><br />\n";
        
        if ($query->recordcount() == 0)
        {
            echo "No items found! Try changing your search criteria.";
        }
        else
        {
            while ($item = $query->fetchrow())
            {
                echo "<fieldset>\n";
                echo "<legend><b>" . $item['name'] . "</b></legend>\n";
                echo "<table width=\"100%\">\n";
                echo "<tr><td width=\"85%\">";
                echo $item['descript'] . "\n<br />";
                echo "</td><td width=\"15%\">";
                echo "<b>Price:</b> " . $item['price'] . "<br />";
                echo "<a href=\"shop.php?act=buy&id=" . $item['id'] . "\">Buy</a><br />";
                echo "</td></tr>\n";
                echo "</table>";
                echo "</fieldset>\n<br />";
            }
        }
        
        break;
    
    case "shoulders":
        //Check in case somebody entered 0
        $_GET['fromprice'] = ($_GET['fromprice'] == 0)?"":$_GET['fromprice'];
        $_GET['toprice'] = ($_GET['toprice'] == 0)?"":$_GET['toprice'];
        
        //Construct query
        $query = "select `id`, `name`, `slot`, `price`, `type`, `bonus`, `target`, `attr`, `effect`, `value`, `descript` from `items` where ";
        $query .= ($_GET['name'] != "")?"`name` LIKE  ? and ":"";
        $query .= ($_GET['fromprice'] != "")?"`price` >= ? and ":"";
        $query .= ($_GET['toprice'] != "")?"`price` <= ? and ":"";        
        $query .= "`slot`='shoulders' order by `price` asc";
        
        //Construct values array for adoDB
        $values = array();
        if ($_GET['name'] != "")
        {
            array_push($values, "%".trim($_GET['name'])."%");
        }
        if ($_GET['fromprice'])
        {
            array_push($values, intval($_GET['fromprice']));
        }
        if ($_GET['toprice'])
        {
            array_push($values, intval($_GET['toprice']));
        }
        
        $query = $db->execute($query, $values); //Search!
        
        $q = $db->execute("select * from `users` where `id`=?", array($player->id));
        $r = $q->fetchrow();        
        if($r['gender'] == 'male'){$sirmad = 'sir';}else{$sirmad = 'madam';}    
        echo "<fieldset>";
        echo "<legend><b>Shop Keeper:</b></legend>\n";
        echo "<i>What would you like to see, ".$sirmad."?</i><br /><br />\n";
        echo "<form method=\"get\" action=\"shop.php\">\n";
        echo "<table width=\"100%\">\n";
        echo "<tr>\n<td width=\"40%\">Name:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"name\" value=\"" . stripslashes($_GET['name']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Price:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"fromprice\" size=\"4\" value=\"" . stripslashes($_GET['fromprice']) . "\" /> to <input type=\"text\" name=\"toprice\" size=\"4\" value=\"" . stripslashes($_GET['toprice']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Type:</td>\n";
        echo "<td width=\"60%\"><select name=\"act\" size=\"2\">\n";
        echo "<option value=\"weapon\">Weapons</option>\n";
        echo "<option value=\"head\">Headgear</option>\n";
        echo "<option value=\"shield\">Shields</option>\n";
        echo "<option value=\"neck\">Neck</option>\n";
        echo "<option value=\"shoulders\"  selected=\"selected\">Shoulders</option>\n";
        echo "<option value=\"body\">Body</option>\n";
        echo "<option value=\"arm\">Arms</option>\n";
        echo "<option value=\"wrists\">Wrist</option>\n";
        echo "<option value=\"hands\">Hands</option>\n";
        echo "<option value=\"finger\">Fingers</option>\n";
        echo "<option value=\"legs\">Legs</option>\n";
        echo "<option value=\"feet\">Feet</option>\n";
        echo "<option value=\"pet\">Pets</option>\n";
        echo "</select></td>\n</tr>\n";
        echo "<tr>\n<td></td>";
        echo "<td><input type=\"submit\" value=\"Submit\" /></td>\n</tr>";
        echo "</table>";
        echo "</form>\n";
        echo "</fieldset>";
        echo "<br /><br />";
        echo "<b>Shop Keeper:</b><br />\n";
        echo "<i>Here's our collection:</i><br /><br />\n";
        
        if ($query->recordcount() == 0)
        {
            echo "No items found! Try changing your search criteria.";
        }
        else
        {
            while ($item = $query->fetchrow())
            {
                echo "<fieldset>\n";
                echo "<legend><b>" . $item['name'] . "</b></legend>\n";
                echo "<table width=\"100%\">\n";
                echo "<tr><td width=\"85%\">";
                echo $item['descript'] . "\n<br />";
                echo "</td><td width=\"15%\">";
                echo "<b>Price:</b> " . $item['price'] . "<br />";
                echo "<a href=\"shop.php?act=buy&id=" . $item['id'] . "\">Buy</a><br />";
                echo "</td></tr>\n";
                echo "</table>";
                echo "</fieldset>\n<br />";
            }
        }
        
        break;
        
    default:
            $q = $db->execute("select * from `users` where `id`=?", array($player->id));
        $r = $q->fetchrow();
        if($r['gender'] == 'male'){$sirmad = 'sir';}else{$sirmad = 'madam';}
        //Show search form
        echo "<fieldset>";
        echo "<legend><b>Shop Keeper:</b></legend>\n";
        echo "<i>What would you like to see, ".$sirmad."?</i><br /><br />\n";
        echo "<form method=\"get\" action=\"shop.php\">\n";
        echo "<table width=\"100%\">\n";
        echo "<tr>\n<td width=\"40%\">Name:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"name\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Price:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"fromprice\" size=\"4\" /> to <input type=\"text\" name=\"toprice\" size=\"4\" /></td>\n";
        echo "</td>\n</tr>";            
        echo "<tr>\n<td width=\"40%\">Type:</td>\n";
        echo "<td width=\"60%\"><select name=\"act\" size=\"2\">\n";
        echo "<option value=\"weapon\" selected=\"selected\">Weapons</option>\n";
        echo "<option value=\"head\">Headgear</option>\n";
        echo "<option value=\"shield\">Shields</option>\n";
        echo "<option value=\"neck\">Neck</option>\n";
        echo "<option value=\"shoulders\">Shoulders</option>\n";
        echo "<option value=\"body\">Body</option>\n";
        echo "<option value=\"arm\">Arms</option>\n";
        echo "<option value=\"wrists\">Wrist</option>\n";
        echo "<option value=\"hands\">Hands</option>\n";
        echo "<option value=\"finger\">Fingers</option>\n";
        echo "<option value=\"legs\">Legs</option>\n";
        echo "<option value=\"feet\">Feet</option>\n";
        echo "<option value=\"pet\">Pets</option>\n";
        echo "</select></td>\n</tr>\n";
        echo "<tr>\n<td></td>";
        echo "<td><input type=\"submit\" value=\"Submit\" /></td>\n</tr>";
        echo "</table>";
        echo "</form>\n";
        echo "</fieldset>";
        break;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/195157-long-topic-query-is-not-working/
Share on other sites

Yes, as you say - long topic.

 

What we need is a short piece of code that is not working as you expect so that we can just look at that and point out your syntax error or statement error. If you post a large chunk of code, no-one will bother to go into it to get into the design, and code.

 

So, narrow down the problem to a short piece of sql perhaps and then we will be able to help. That way, you get to find out where the problem is and post it on here so that we can help.

I don't know what the problem is. It's not syntax at all.. It's basically something to say you cant purchase more than 1 item but there is nothing like that.

        $q1 = $db->execute("select * from `inventory` where `player`=? and item_id=?", array($player->id,$_GET['id']));
        if($q1->recordcount() == 0)
        {
        echo 'error<br />'; //This shows up on all attempts of buying a different item
        $query2 = mysql_query("insert into `inventory` (player, quantity, status, item_id, type) values ('".$player->id."','0','unequipped','".$_GET['id']."','".$item['type']."')"); // This just gets ignored, no other rows get entered nothing at all, on all attempts of buying a different item 
        }

 

I don't know what the exact problem is so thats why I posted the whole code.

What I normally do is to display the generated query and stop the program.

 

Then I copy and paste the generated query into mysql and run it to see if there actually ARE any items selected. You will probably find like I often do, that the generated query is not what you expected (maybe because the variables do not contain what you want) and the statement is doing exactly as you have asked but returning no rows.

 

 

I understand, but $player->id is used all over so it is obvious it works. As for item id, it's displayd in the URL.

Can't go wrong.

The problem is.. It ddoes what it's suppose to, selects something from the database and if there is no rows to echo "error" but it should insert into the database too, but it doesn't. I really don't know the problem.

Someone has to know something? I tried changed the method slightly.

	$q1 = $db->execute("select * from `inventory` where `player`=? and item_id=?", array($player->id,$item['id']));
	if($q1->recordcount() == 0)
	{
	echo 'Error,';
	$insert['player'] = $player->id;
	$insert['quantity'] = '0';
	$insert['status'] = 'unequipped';
	$insert['item_id'] = $item['id'];
	$insert['type'] = $item['type'];

	$query2 = $db->autoexecute('inventory', $insert, 'INSERT'); 
	if($query2){ echo 'The query went into the database<br />'; } else { echo 'the query didnt take place<br />'; }
	}

 

If there isn't any items at all under the player name in the database, it'll say "Error, the query went into the database" which is perfect. Though if there is items in the database under the player name, it'll check for the item ID and if there isn't a row with the item id and the player name then it SHOULD insert it,

instead.. it echo's "Error the query didn't take place"

 

Is this more help to you? It's just basically skipping the query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.