Connecting Tech Pros Worldwide Forums | Help | Site Map

Send value from Flash to database with PHP

Newbie
 
Join Date: May 2007
Posts: 11
#1: Jun 4 '07
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.php)
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $nick = $_POST['Nick'];
  3. $score = $_POST['Score'];
  4. $kills = $_POST['Kills'];
  5. $floor = $_POST['FloorNr'];
  6.  
  7. $db=mysql_connect("")
  8. or die("Couldn't connect.");
  9. mysql_select_db("databasename", $db);
  10.  
  11. mysql_query("INSERT INTO Table (Nickname,Score,Kills,Floor) VALUES ('$nick','$score','$kills','$floor')",$db);
  12.  
  13. mysql_close($db);
  14. echo "Your score has been submited! ";
  15. ?>
  16.  
Actionscript:
Expand|Select|Wrap|Line Numbers
  1. myData = new LoadVars();
  2. myData.Nick = nickname.text;
  3. myData.Score = _global.score;
  4. myData.Kills = _global.TotalKills;
  5. myData.FloorNr = _global.floorNr;
  6.  
  7. myData.send("submitScore.php", myData, "POST");
  8.  
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's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Jun 4 '07

re: Send value from Flash to database with PHP


You could set up a unique key in your MySQL database to disallow duplicate posts.
Motoma's Avatar
Moderator
 
Join Date: Jan 2007
Location: Maine, USA
Posts: 2,904
#3: Jun 5 '07

re: Send value from Flash to database with PHP


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.
Reply