MasterACE14 Posted July 3, 2008 Share Posted July 3, 2008 Hi guys, I have a Armoury and Inventory system for my game. The Armoury is working fine. Players can buy weapons at the Armoury, and thats put in the MySQL database. Now, when they go to equip, or sell there weapon in the Inventory page. It doesn't want to work. When a player presses the "Equip" link next to there weapon, it goes to Inventory.php with the $_GET['id'] but nothing happens. and When a player presses the "Sell" link next to there weapon, it goes to Armoury.php with the $_GET[]'s but it returns this message: Sorry, that item does not exist! here is the relevent code to "Equip": <?php player_session(); $player = player_table($_SESSION['playerid']); if ($_GET['id']) { $query = @mysql_query("SELECT `status`, `item_id` FROM `items` WHERE `id`='" . $_GET['id'] . "' AND `player_id`='" . $player['id'] . "'"); $query2 = @mysql_query("SELECT * FROM `items`, `blueprint_items` WHERE items.item_id = blueprint_items.id AND blueprint_items.type=(SELECT `type` FROM `blueprint_items` WHERE `id`='" . $item['item_id'] . "') AND items.player_id='" . $player['id'] . "' AND `status`='equipped'"); if (mysql_num_rows($query) == 1) { $item = mysql_fetch_array($query); $bpi = mysql_fetch_array($query2); switch($bpi['type']) { // weapon case "weapon": $type = "weapon"; $action = "strikeaction"; break; // armour case "armour": $type = "armour"; $action = "defenceaction"; break; // vehicle case "vehicle": $type = "vehicle"; $action = "covertaction"; break; } switch($item['status']) { case "unequipped": //User wants to equip item $itemtype = @mysql_query("SELECT `type` FROM `blueprint_items` WHERE `id`='" . $item['item_id'] . "'"); //Check if another item is already equipped $unequip = @mysql_query("SELECT items.id FROM `items`, `blueprint_items` WHERE items.item_id = blueprint_items.id AND blueprint_items.type=(SELECT `type` FROM `blueprint_items` WHERE `id`='" . $item['item_id'] . "') AND items.player_id='" . $player['id'] . "' AND `status`='equipped'"); if ($unequip) //If so, then unequip it (only one item may be equipped at any one time) { $query = @mysql_query("UPDATE `items` SET `status`='unequipped' WHERE `id`='" . $unequip . "'"); $query2 = @mysql_query("UPDATE `cf_users` SET `" . $action . "`=`" . $action . "`-'" . $bpi['effectiveness'] . "' WHERE `id`='" . $unequip . "'"); # take away the strike/defence or covert action } //Equip the selected item $query = @mysql_query("UPDATE `items` SET `status`='equipped' WHERE `id`='" . $_GET['id'] . "'"); $query2 = @mysql_query("UPDATE `cf_users` SET `" . $action . "`=`" . $action . "`+'" . $bpi['effectiveness'] . "' WHERE `id`='" . $_GET['id'] . "'"); # add the strike/defence or covert action break; case "equipped": //User wants to unequip item $query = @mysql_query("UPDATE `items` SET `status`='unequipped' WHERE `id`='" . $_GET['id'] . "'"); $query2 = @mysql_query("UPDATE `cf_users` SET `" . $action . "`=`" . $action . "`-'" . $bpi['effectiveness'] . "' WHERE `id`='" . $unequip . "'"); # take away the strike/defence or covert action break; default: //Set status to unequipped, in case the item had no status when it was inserted into db $query = @mysql_query("UPDATE `items` SET `status`='unequipped' WHERE `id`='" . $_GET['id'] . "'"); break; } } } ?> <b>Weapons:</b> <br /><br /> <?php $query = @mysql_query("SELECT * FROM `items`, `blueprint_items` WHERE blueprint_items.id=items.item_id AND items.player_id='" . $player['id'] . "' AND blueprint_items.type='weapon' ORDER BY items.status ASC"); if (mysql_num_rows($query) == 0) { echo "<br /><b>You have no weapons.</b>"; } else { while($item = mysql_fetch_array($query)) { echo "<fieldset>\n<legend>"; echo "<b>" . $item['name'] . "</b></legend>\n"; echo "<table width=\"100%\">\n"; echo "<tr><td width=\"85%\">"; echo $item['description'] . "\n<br />"; echo "<b>Effectiveness:</b> " . $item['effectiveness'] . "\n"; echo "</td><td width=\"15%\">"; echo "<a href=\"index.php?page=armoury&act=sell&id=" . $item['id'] . "\">Sell</a><br />"; echo "<a href=\"index.php?page=inventory&id=" . $item['id'] . "\">"; echo ($item['status'] == "equipped")?"Unequip":"Equip"; echo "</a>"; echo "</td></tr>\n"; echo "</table>"; echo "</fieldset>\n<br />"; } } ?> sorry there is a fair bit of code relevant to the problem :-\ and here is the code related to "Sell" and the relevant code in Armoury.php: <?php case "sell": if (!$_GET['id']) //No item ID { header("Location: index.php?page=armoury"); break; } //Select the item from the database $query = @mysql_query("SELECT * FROM `blueprint_items`, `items` WHERE items.item_id=blueprint_items.id AND items.player_id='" . $player['id'] . "' and items.id='" . $_GET['id'] . "'"); //Either item doesn't exist, or item doesn't belong to user if (mysql_num_rows($query) == 0) { echo "Sorry, that item does not exist!"; break; } $sell = mysql_fetch_array($query); //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> money?<br /><br />\n"; echo "<form method=\"post\" action=\"index.php?page=armoury&act=sell&id=" . $sell['id'] . "\">\n"; echo "<input type=\"submit\" name=\"sure\" value=\"Yes, I am sure!\" />\n"; echo "</form>\n"; break; } //Delete item from database, add money to player's account $query = @mysql_query("DELETE FROM `items` WHERE `id`='" . $sell['id'] . "'"); $query = @mysql_query("UPDATE `cf_users` SET `money`='" . $player['money'] + floor($sell['price']/2) . "' WHERE `id`='" . $player['id'] . "'"); Any help is greatly appreciated. Regards ACE Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 3, 2008 Author Share Posted July 3, 2008 a few hours of experimentation and nothing yet :-\ Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 I have a quick question, sorry. Does this: $player = player_table($_SESSION['playerid']); Do what I think it does? Are you reloading all of the person's info on every single page when it can be just as easily put into the session to save load times? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 4, 2008 Author Share Posted July 4, 2008 this is the function: <?php // Select fields from other users table function player_table($id=null){ if($id == null) { $id = $_SESSION['playerid']; } $sql = "SELECT * FROM cf_users,cf_users2 WHERE cf_users.id= '$id' && cf_users2.id= '$id' LIMIT 1"; $rs = @mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); $row = mysql_fetch_assoc($rs); return $row; }; Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 4, 2008 Share Posted July 4, 2008 <?php // Select fields from other users table function player_table($id=NULL;){ if($id == NULL) { $id = $_SESSION['playerid']; } $sql = "SELECT * FROM cf_users,cf_users2 WHERE cf_users.id= '$id' && cf_users2.id= '$id' LIMIT 1"; $rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error()); $row = mysql_fetch_assoc($rs); return $row; };?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 4, 2008 Author Share Posted July 4, 2008 The function isn't the problem lol. I was just showing DarkWater. these are the 2 problems relating to the other 2 codes: When a player presses the "Equip" link next to there weapon, it goes to Inventory.php with the $_GET['id'] but nothing happens. and When a player presses the "Sell" link next to there weapon, it goes to Armoury.php with the $_GET[]'s but it returns this message: Sorry, that item does not exist! Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 4, 2008 Share Posted July 4, 2008 have you tried <?php $num_rows= mysql_num_rows($query); if($num_rows<1){ //error }?> Quote Link to comment Share on other sites More sharing options...
Juan Dela Cruz Posted July 4, 2008 Share Posted July 4, 2008 can you remove all those @ signs so you can see the actual error,and paste here if error occur Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 4, 2008 Share Posted July 4, 2008 and Juan is right the @ causes error to not display Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 4, 2008 Author Share Posted July 4, 2008 When I press "Sell" it's still showing: Sorry, that item does not exist! When I press "Equip" it's still loading the same page with no change. No mysql errors even after removing all @'s Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 5, 2008 Author Share Posted July 5, 2008 Anyone? I've gone through it again and again, and can't find the culprit for these 2 problems :-\ Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 have you put on error reporting? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 5, 2008 Author Share Posted July 5, 2008 I just put error reporting on(E_ALL). In armoury.php it has this: Notice: Undefined index: act in /home/ace/public_html/conflictingforces/lib/armoury.php on line 7 in inventory.php is has this: Notice: Undefined index: id in /home/ace/public_html/conflictingforces/lib/inventory.php on line 8 Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 5, 2008 Author Share Posted July 5, 2008 I've put isset() around the $_GET's in armoury.php and inventory.php. Now when I press "Sell" , it actually buys another weapon. Instead of Selling one I already have. and when I press "Equip" it gives me this message: Notice: Undefined variable: item in /home/ace/public_html/conflictingforces/lib/inventory.php on line 11 Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 5, 2008 Share Posted July 5, 2008 can you paste the relevant coede please ??? Quote Link to comment Share on other sites More sharing options...
compguru910 Posted July 5, 2008 Share Posted July 5, 2008 Try this with your query if (mysql_query($query)) { blah blah } else { print "There was an error with MySQL, the error was " . mysql_error() . " The query was " . $query; } Thats a great debugging script for MySQL. IF you are using PHPmyadmin, then you can past that query that it submitted into the SQL section of PHPmyAdmin, and it will show you the results, if any. That way you can see if it is a q Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 9, 2008 Author Share Posted July 9, 2008 It's exactly the same as it was in my very first post at the top. Only difference is where !$_GET['id'] is. Its now !isset($_GET['id']) 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.