Send value from Flash to database with PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • molle
    New Member
    • May 2007
    • 11

    Send value from Flash to database with PHP

    Hi!

    This has been posted in the flash-forum as well.

    I know a solution for this problem and that is using this code:

    PHP: (submitScore.ph p)
    [code=php]
    <?php
    $nick = $_POST['Nick'];
    $score = $_POST['Score'];
    $kills = $_POST['Kills'];
    $floor = $_POST['FloorNr'];

    $db=mysql_conne ct("")
    or die("Couldn't connect.");
    mysql_select_db ("databasename" , $db);

    mysql_query("IN SERT INTO Table (Nickname,Score ,Kills,Floor) VALUES ('$nick','$scor e','$kills','$f loor')",$db);

    mysql_close($db );
    echo "Your score has been submited! ";
    ?>
    [/code]

    Actionscript:
    [code=actionscri pt]
    myData = new LoadVars();
    myData.Nick = nickname.text;
    myData.Score = _global.score;
    myData.Kills = _global.TotalKi lls;
    myData.FloorNr = _global.floorNr ;

    myData.send("su bmitScore.php", myData, "POST");
    [/code]

    The problem with this is that submitScore.php pops up in the browser so that
    the player can just refresh the submitScore.php page and in such a way
    repeat the insert query to the database, adding the score several times.
    Either I can make the page close down on its own or is there a way to insert a
    value to a database without making the submitScore.php pup up and accessible
    to the user?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    You could set up a unique key in your MySQL database to disallow duplicate posts.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Have the submitScore page do the update, then redirect to a message screen. When the page is refreshed, it will just the the message screen, and not the submission.

      Comment

      Working...