Strider64 Posted March 7, 2015 Share Posted March 7, 2015 I wrote a game in Flash Actionscript 3 about three years ago and I'm in the progress of updating my php code from old mysql to PDO. I have the scores inserting correctly from Actionscript to the Database Table. However, Deleting the lowest score doesn't seem to work, normally I can debug what is wrong, but the game runs in Flash. I think it's a logic error more than anything else. I kind of want to dust off this game, so I can improve the game play and the graphics. Here's is the short php code that transfer over from actionscript to the database. <?php include("bouncyballdbs.php"); $lowestHighScore = $_POST['lowestHighScore']; $id = $_POST['id']; $todaydate = date('Y-m-d H:i:s', strtotime($_POST['todaydate'])); $playername = $_POST['playername']; $playerscore = $_POST['playerscore']; $insertScore = 'INSERT INTO ' . DATABASE_TABLE . '( todaydate, playername, playerscore ) VALUES ( :todaydate, :playername, :playerscore )'; $insertParams = array( ':todaydate' => $todaydate, ':playername' => $playername, ':playerscore' => $playerscore ); $stmt = $pdo->prepare($insertScore); $stmt->execute($insertParams); $query = 'DELETE FROM ' . DATABASE_TABLE . ' WHERE playerscore < :lowestHighScore'; $stmt = $pdo->prepare($query); $stmt->bindParam(':lowestHighScores', $lowestHighScore, PDO::PARAM_INT); $stmt->execute(); The $id is no longer use and I should probably just take that out of the script. Thanks in advance, John Link to comment https://forums.phpfreaks.com/topic/295159-high-scores-display/ Share on other sites More sharing options...
mac_gyver Posted March 7, 2015 Share Posted March 7, 2015 you have a typo in the place-holder name. query :lowestHighScore vs bind statement :lowestHighScores, which should be producing an error at the bind or execute statement, depending on if emulated prepared queries are on/off. your error handling logic should be logging the error information for you to use for debugging. Link to comment https://forums.phpfreaks.com/topic/295159-high-scores-display/#findComment-1507849 Share on other sites More sharing options...
Strider64 Posted March 7, 2015 Author Share Posted March 7, 2015 Thanks, I didn't think of the error logging....duh. However, I think that is what the problem is and if not I know now of error logging. Thanks Again. Link to comment https://forums.phpfreaks.com/topic/295159-high-scores-display/#findComment-1507850 Share on other sites More sharing options...
Strider64 Posted March 8, 2015 Author Share Posted March 8, 2015 That was the major blunt of the problem, I still had a little logic error in the script though. However, fixing all the errors helped narrow it down. If anyone wonders what the solution is, here it is: <?php include("bouncyballdbs.php"); $lowestHighScore = $_POST['lowestHighScore']; $todaydate = date('Y-m-d H:i:s', strtotime($_POST['todaydate'])); $playername = $_POST['playername']; $playerscore = $_POST['playerscore']; $insertScore = 'INSERT INTO ' . DATABASE_TABLE . '( todaydate, playername, playerscore ) VALUES ( :todaydate, :playername, :playerscore )'; $insertParams = array( ':todaydate' => $todaydate, ':playername' => $playername, ':playerscore' => $playerscore ); $stmt = $pdo->prepare($insertScore); $stmt->execute($insertParams); try { /* I had to make it a <= symbol and set the limit to 1, for I only add 1 if the player gets */ /* a high score */ $query = 'DELETE FROM ' . DATABASE_TABLE . ' WHERE playerscore <= :lowestHighScore LIMIT 1'; $stmt = $pdo->prepare($query); $stmt->bindParam(':lowestHighScore', $lowestHighScore, PDO::PARAM_INT); $stmt->execute(); } catch (PDOException $e) { // Report the Error! error_log($e->getMessage(), 3, ERRORLOG_PATH); } Link to comment https://forums.phpfreaks.com/topic/295159-high-scores-display/#findComment-1507852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.