Jump to content

High Scores Display


Strider64
Go to solution Solved by mac_gyver,

Recommended Posts

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
Share on other sites

  • Solution

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.