MasterACE14 Posted November 23, 2007 Share Posted November 23, 2007 Morning Everyone, I have a script which is suppose to UPDATE a user in the database depending on which button they pressed on the previous page. But it doesn't seem to be running the UPDATE query at all. here's my script. <?php // armory player_session(); /**********************/ // Player Select Variables // /**********************/ // User Information $player_accountid = player_table("id"); $player_username = player_table("username"); // money $player_money = player_table("money"); // Inventory $player_weaponid = player_table("weaponid"); $player_armorid = player_table("armorid"); $player_vehicleid = player_table("vehicleid"); $player_weapons = player_table("weapons"); $player_armors = player_table("armors"); $player_vehicles = player_table("vehicles"); // Equipped Items // Names $equippedweaponname = select_array($weapons,$player_weaponid,"weapon"); $equippedarmorname = select_array($armors,$player_armorid,"armor"); $equippedvehiclename = select_array($vehicles,$player_vehicleid,"vehicle"); // ID $equippedweaponid = select_array($weapons,$player_weaponid,"id"); $equippedarmorid = select_array($armors,$player_armorid,"id"); $equippedvehicleid = select_array($vehicles,$player_vehicleid,"id"); // Purchase Weapon $_POST's $item_bought = addslashes($_POST["buy"]); $item_price = addslashes($_POST["itemprice"]); $item_type = addslashes($_POST["itemtype"]); $item_id = addslashes($_POST["itemid"]); /* database connection has been made on the page included before this one. */ ?> <div id = "base"> <center><b><u>Armory</u></b><br></center><br> <!-- Left Column --> <div id = "leftcolumn"> <div id = "inventory_items"> <?php if($player_money < $item_price) { die("<b>You do not have enough money!</b>"); } else { // current money - weapon price = your new money $new_money = $player_money - $item_price; // run the queries for you - insert your new amount of money $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1"; $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error()); // check if it is a weapon, armor, or vehicle if($item_type == 'weapon') { $type = 'weapons'; }elseif ($item_type == 'armor') { $type = 'armors'; }elseif ($item_type == 'vehicle') { $type = 'vehicles'; } // run the queries for you - give you your weapon $typex = $type . ',' . $item_id; $update = "UPDATE `cf_users` SET `$type` = '$typex' WHERE `id`='" . $player_accountid . "' LIMIT 1"; $query = mysql_query($update) or die('Query:<br />' . $sqlll . '<br /><br />Error:<br />' . mysql_error()); ?> <?php /* Grab weapon Array and Display it */ foreach ($weapons as $key => $val) { if($item_bought == $val[$item_id]){ echo '<table class="fix"><tr>'; if($item_bought == "weapons"){ $x= 'weapon'; } elseif($item_bought == "armors"){ $x= 'armor'; } elseif($item_bought == "vehicles"){ $x= 'vehicle'; } echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>'; echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>'; if($item_bought == "weapons"){ $y= 'damage'; } elseif($item_bought == "armors"){ $y= 'defence'; } elseif($item_bought == "vehicles"){ $y= 'power'; } echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>'; echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>'; echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>'; echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>'; echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>'; echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>'; echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>'; echo '<td colspan="2"><b> Purchase Successful! </b></td></tr>'; echo '</table><br />'; } } ?> <?php /* Grab weapon Array and Display it */ foreach ($armors as $key => $val) { if($item_bought == $val[$item_id]){ echo '<table class="fix"><tr>'; if($item_bought == "weapons"){ $x= 'weapon'; } elseif($item_bought == "armors"){ $x= 'armor'; } elseif($item_bought == "vehicles"){ $x= 'vehicle'; } echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>'; echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>'; if($item_bought == "weapons"){ $y= 'damage'; } elseif($item_bought == "armors"){ $y= 'defence'; } elseif($item_bought == "vehicles"){ $y= 'power'; } echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>'; echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>'; echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>'; echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>'; echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>'; echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>'; echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>'; echo '<td colspan="2"><b> Purchase Successful! </b></td></tr>'; echo '</table><br />'; } } ?> <?php /* Grab weapon Array and Display it */ foreach ($vehicles as $key => $val) { if($item_bought == $val[$item_id]){ echo '<table class="fix"><tr>'; if($item_bought == "weapons"){ $x= 'weapon'; } elseif($item_bought == "armors"){ $x= 'armor'; } elseif($item_bought == "vehicles"){ $x= 'vehicle'; } echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>'; echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>'; if($item_bought == "weapons"){ $y= 'damage'; } elseif($item_bought == "armors"){ $y= 'defence'; } elseif($item_bought == "vehicles"){ $y= 'power'; } echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>'; echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>'; echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>'; echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>'; echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>'; echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>'; echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>'; echo '<td colspan="2"><b> Purchase Successful! </b></td></tr>'; echo '</table><br />'; } } } // end the 'else' statement ?> </div> </div> <!-- Right Column --> <div id = "rightcolumn"> </div> Any help is greatly appreciated. Regards ACE Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 If they pressed a button from a prev page, we should see you grabbing the POST or GET data, and then act on it. I don't see any references here for a POST or GET variable. Can you give us more information to work with? PhREEEk Quote Link to comment Share on other sites More sharing options...
trq Posted November 24, 2007 Share Posted November 24, 2007 You might also try narrowing your post down to the code that is relevent. I for one don't want to sift through a hundred lines of code. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 24, 2007 Author Share Posted November 24, 2007 Here's 1 of the buttons on the previous page: <form name="armory" method="post" action="index.php?page=armory_result"> <input type="hidden" name="itemid" value="<?=$weapons[$key]['id'];?>"> <input type="hidden" name="itemprice" value="<?=$weapons[$key]['price'];?>"> <input type="hidden" name="itemtype" value="weapon"> <input type="submit" name="buy" value="Buy <?=$weapons[$key]['weapon'];?>"> </form> Note when I view the page source all the value's are correct. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Should be fairly simple... change: <?php // run the queries for you - insert your new amount of money $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1"; to: <?php // run the queries for you - insert your new amount of money $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1"; die("$sqll"); Analyze that output for any obvious problems. If you don't see any, open up phpMyAdmin. Copy that screen output and paste it directly into a SQL box in phpMyAdmin. See if it returns an 'Affected Rows' of 0 or 1. Post back your results. PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 24, 2007 Author Share Posted November 24, 2007 It died and echo'd: UPDATE `cf_users` SET `money` = '40587440181' WHERE `id`='1' LIMIT 1 The query executed with no problem at all in phpMyAdmin. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Ok, next stage: <?php // run the queries for you - insert your new amount of money $sqll = "UPDATE `cf_users` SET `money` = '$new_money' WHERE `id`='" . $player_accountid . "' LIMIT 1"; $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error()); echo "Numer of records updated: " . mysql_affected_rows(); die(); PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 24, 2007 Author Share Posted November 24, 2007 Numer of records updated: 1 Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Run this: <?php // run the queries for you - insert your new amount of money $sqll = "UPDATE `cf_users` SET `money` = '0' WHERE `id`='" . $player_accountid . "' LIMIT 1"; $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error()); echo "Numer of records updated: " . mysql_affected_rows(); die(); If you get 1 affected row, open phpMyAdmin and check the record for that ID. Does money = 0? If not, we need Fox Mulder again... PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 24, 2007 Author Share Posted November 24, 2007 It said 1 affected row again and money is greater then 0 Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Last try, then I'm all about 'Uncle'... <?php // run the queries for you - insert your new amount of money $sqll = "SELECT * FROM `cf_users` WHERE `id`='" . $player_accountid . "' LIMIT 1"; $result = mysql_query($sqll); $row = mysql_fetch_assoc($result); echo "Before Update:<br><pre>"; print_r($row); echo "</pre><br>After Update:<br><pre>"; $sqll = "UPDATE `cf_users` SET `money` = '0' WHERE `id`='" . $player_accountid . "' LIMIT 1"; $rss = mysql_query($sqll) or die('Query:<br />' . $sqll . '<br /><br />Error:<br />' . mysql_error()); $updated = mysql_affected_rows(); $sqll = "SELECT * FROM `cf_users` WHERE `id`='" . $player_accountid . "' LIMIT 1"; $result = mysql_query($sqll); $row = mysql_fetch_assoc($result); print_r($row); echo "</pre><br><br>Number of records updated: $updated"; die(); PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 24, 2007 Author Share Posted November 24, 2007 Before Update: Array ( [id] => 1 [username] => ACE [password] => My Password => My E-mail [verify] => 5 [race] => 3 [money] => 45097155040 [bank] => 1000 [level] => 1 [currentexp] => 0 [neededexp] => 120 [authlevel] => 3 [currenthealth] => 100 [currentpower] => 100 [maxhealth] => 100 [maxpower] => 100 [skilllevel] => 1 [skillpoints] => 3 [strength] => 10 [agility] => 10 [intelligence] => 10 [strikeaction] => 2147483647 [defenceaction] => 2147483647 [covertaction] => 2147483647 [talentid] => 0 [talentname] => none [talentlevel] => 1 [talentpoints] => 0 [weaponid] => 0 [weapons] => 0 [armorid] => 0 [armors] => 0 [vehicleid] => 0 [vehicles] => 0 [allianceid] => 0 [alliancename] => none [allianceposition] => 0 [regdate] => 2007-09-25 20:11:35 [ammo] => 2072 [rank] => 24 [price_strikeops] => 134217728000 [amount_strikeops] => 53687091200 [level_strikeops] => 30 [level_defenceops] => 33 [amount_defenceops] => 429496729600 [price_defenceops] => 1073741824000 [price_covertops] => 134217728000 [amount_covertops] => 53687091200 [level_covertops] => 30 [score] => 2147483647 ) After Update: Array ( [id] => 1 [username] => ACE [password] => My Password => My E-mail [verify] => 5 [race] => 3 [money] => 0 [bank] => 1000 [level] => 1 [currentexp] => 0 [neededexp] => 120 [authlevel] => 3 [currenthealth] => 100 [currentpower] => 100 [maxhealth] => 100 [maxpower] => 100 [skilllevel] => 1 [skillpoints] => 3 [strength] => 10 [agility] => 10 [intelligence] => 10 [strikeaction] => 2147483647 [defenceaction] => 2147483647 [covertaction] => 2147483647 [talentid] => 0 [talentname] => none [talentlevel] => 1 [talentpoints] => 0 [weaponid] => 0 [weapons] => 0 [armorid] => 0 [armors] => 0 [vehicleid] => 0 [vehicles] => 0 [allianceid] => 0 [alliancename] => none [allianceposition] => 0 [regdate] => 2007-09-25 20:11:35 [ammo] => 2072 [rank] => 24 [price_strikeops] => 134217728000 [amount_strikeops] => 53687091200 [level_strikeops] => 30 [level_defenceops] => 33 [amount_defenceops] => 429496729600 [price_defenceops] => 1073741824000 [price_covertops] => 134217728000 [amount_covertops] => 53687091200 [level_covertops] => 30 [score] => 2147483647 ) Number of records updated: 1 Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Money before = [money] => 45097155040 Money after = [money] => 0 Update successful. PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 24, 2007 Author Share Posted November 24, 2007 I've got it taking away the correct amount of money now, but it still doesn't show the table for the item you purchased, nor does it put the ID of the item into the database :-\ Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 24, 2007 Share Posted November 24, 2007 Run this code: <?php // run the queries for you - give you your weapon $sql = "SELECT `weapons`, `armors`, `vehicles` FROM `cf_users` WHERE `id`= '" . $player_accountid . "' LIMIT 1 "; $result = mysql_query($sql); list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result); $typex = $type . ',' . $item_id; $update = "UPDATE `cf_users` SET `$type` = '$typex' WHERE `id`='" . $player_accountid . "' LIMIT 1"; echo "Before Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>"; echo "Performing Update using query: <br>$update<br><br>"; $query = mysql_query($update) or die('Query:<br />' . $sqlll . '<br /><br />Error:<br />' . mysql_error()); $sql = "SELECT `weapons`, `armors`, `vehicles` FROM `cf_users` WHERE `id`= '" . $player_accountid . "' LIMIT 1 "; $result = mysql_query($sql); list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result); echo "After Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>"; die(); PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 28, 2007 Author Share Posted November 28, 2007 here's the result: Before Update: Weapon = Armor = Vehicle = Performing Update using query: UPDATE `cf_users` SET `weapons` = 'weapons,1' WHERE `id`='1' LIMIT 1 After Update: Weapon = Armor = Vehicle = Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 28, 2007 Author Share Posted November 28, 2007 bump Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 28, 2007 Share Posted November 28, 2007 Run this through phpMyAdmin UPDATE `cf_users` SET `weapons` = 'weapons,1' WHERE `id`='1' LIMIT 1 PhREEEk Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 28, 2007 Share Posted November 28, 2007 We might want to try this code too: <?php // run the queries for you - give you your weapon $sql = "SELECT `weapons`, `armors`, `vehicles` FROM `cf_users` WHERE `id`= '" . $player_accountid . "' LIMIT 1 "; $result = mysql_query($sql); list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result); $typex = $type . ',' . $item_id; $update = "UPDATE `cf_users` SET `$type` = '" . mysql_real_escape_string($typex) . "' WHERE `id`='" . $player_accountid . "' LIMIT 1"; echo "Before Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>"; echo "Performing Update using query: <br>$update<br><br>"; $query = mysql_query($update) or die('Query:<br />' . $sqlll . '<br /><br />Error:<br />' . mysql_error()); $sql = "SELECT `weapons`, `armors`, `vehicles` FROM `cf_users` WHERE `id`= '" . $player_accountid . "' LIMIT 1 "; $result = mysql_query($sql); list( $chk_weapon, $chk_armor, $chk_vehicle ) = mysql_fetch_assoc($result); echo "After Update:<br>Weapon = $chk_weapon<br>Armor = $chk_armor<br>Vehicle = $chk_vehicle<br><br>"; die(); PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 30, 2007 Author Share Posted November 30, 2007 Ran the UPDATE through PHPmyAdmin with no success :-\ and made the changes to my code and here is the result: Before Update: Weapon = Armor = Vehicle = Performing Update using query: UPDATE `cf_users` SET `weapons` = 'weapons,2' WHERE `id`='1' LIMIT 1 After Update: Weapon = Armor = Vehicle = Note that, before the UPDATE and after, even if the columns aren't altered, they should still have 0 (zero) in them none the less. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 1, 2007 Author Share Posted December 1, 2007 bump Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 1, 2007 Share Posted December 1, 2007 What would you like to have happen here? If `cf_users` is a valid table, `weapons` is a valid field under `id`-'1', then the query UPDATE `cf_users` SET `weapons` = 'weapons,2' WHERE `id`='1' LIMIT 1 looks good to me. Did you try the mysql_real_escape_string? I guess let's try this. Log into phpMyAdmin and select the table `cf_users`. Click Browse. Under record 'id' 1, click the pencil icon (selecting edit). You are presented with an edit form. Scroll down to the `weapon` field. Type in weapons,2 and save it. Let me know what happens... save any text if it errors out, or is successful. A screenshot would be ideal. PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 1, 2007 Author Share Posted December 1, 2007 Scroll down to the `weapon` field. Type in weapons,2 and save it. Let me know what happens... save any text if it errors out, or is successful. A screenshot would be ideal. where do I type weapons,2 in the weapon field exactly??? screenie: Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 1, 2007 Share Posted December 1, 2007 yep... just type it in (same way you'd want MySQL to insert it) and save... PhREEEk Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 1, 2007 Author Share Posted December 1, 2007 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.