Akenatehm Posted February 7, 2009 Share Posted February 7, 2009 Hey Guys, Here's my code: <?php $host = "localhost"; $name = "username"; $pass = "password"; $db = "badasstoolz"; $con = mysql_connect($host,$name,$pass); if (!$con) { die('Failed to Connect:' . mysql_error()); } $selectdb = mysql_select_db($db); if (!$selectdb) { die('Failed to Select Database:' . mysql_error()); } if(isset($_POST['submitBtn'])) { $charactername = $_POST['charactername']; $charactername = mysql_real_escape_string($charactername); $location = $_POST['location']; $checkdb = mysql_query("SELECT * FROM characters where name = '$charactername'"); if (!$checkdb) { die('Character Name Incorrect:' . mysql_error()); } else { $checkgold = mysql_query("SELECT gold FROM characters WHERE name = '$charactername'"); $gold = mysql_result($checkgold, 0); if (!$checkdb) { die('Could Not Find Gold Amount:' . mysql_error()); } if ($gold < 10000) { echo "Not Enough Gold"; } else{ if($_POST['location'] == "stormwind"){ $move = mysql_query("UPDATE characters SET positionX = '-8913.230469', positionY = '554.632996', positionZ = '93.795525', mapId = '0', zoneId = '1519', orientation = '0.600044' WHERE name = '$charactername'"); } elseif($_POST['location'] == "darnassus"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "ironforge"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "exodar"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "orgrimmar"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "thunderbluff"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "silvermoon"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "undercity"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "dalaran"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } elseif($_POST['location'] == "shattrath"){ $move = mysql_query("UPDATE characters SET positionX = '1502.709961', positionY = '-4415.419922', positionZ = '21.552721', mapId = '1', zoneId = '1637', orientation = '0.000000' WHERE name = '$charactername'"); } else { echo "You did not select a Location"; } if (!$move) { die('Failed to Move Player:' . mysql_error()); } else { $amount = 10000; $query = "UPDATE characters SET gold = gold - " . $amount . " WHERE name = '" . $charactername . "' AND gold >= '" . $amount . "';"; echo "You succesfully moved your character"; } } } } ?> Ok, this script is supposed to get their name from a field (username) that is in another php document, and teleport them to the location they select in a dropdown on the other page (location). It is then supposed to check if they have more then 10,000 gold. if they dont, it should tell them that they don't have enough. if they do, it finds out which location they picked, and updates that in the characters database. Then, if it is succesful, it is supposed to deduct 10,000 gold from their account. This DOESN'T seem to be happening. I put in 100,000 gold in the DB and it says I have enough but 30,000 gold is not enough. AND it is not deducting gold. Help would be great! Cody Quote Link to comment https://forums.phpfreaks.com/topic/144155-solved-selecting-checking-and-subtracting-failing/ Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 first thing I notice is at the end, you aren't actually executing that last query, just assigning it to $query. Quote Link to comment https://forums.phpfreaks.com/topic/144155-solved-selecting-checking-and-subtracting-failing/#findComment-756462 Share on other sites More sharing options...
Akenatehm Posted February 7, 2009 Author Share Posted February 7, 2009 Thanks for that. I fixed that. and now it is deducting. Now I just need it to read it properly. Quote Link to comment https://forums.phpfreaks.com/topic/144155-solved-selecting-checking-and-subtracting-failing/#findComment-756464 Share on other sites More sharing options...
Akenatehm Posted February 7, 2009 Author Share Posted February 7, 2009 Ok. I messed around and saw that it was only not accepting 10,000 and would accept 10,0001 so I have set the required amount to 9,999 which shud fix that. Quote Link to comment https://forums.phpfreaks.com/topic/144155-solved-selecting-checking-and-subtracting-failing/#findComment-756466 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.