Export SWF data form to database MySql using PHP script

 

The purpose is to show how to record data, got from a swf form, in a MySQL database using a PHP script.

The process to building a form has been mentioned. ⇒ See it again.
I 'll just show you which stuff you need to change.

Creating Objects

You should get something like that :

1 - Set up movie size 640x280 and background color #000066. Any Frame Rate.

2 - It's almost the same as in the example mentioned above. Just follow images !

   

   

SwishMax scripts

In Outline, select Scene, get into Expert Mode. Enter the following script :

function reset()
{ adversaire = ""; date1= ""; style = ""; scores = ""; }
onFrame (20,afterPlacedObjectEvents) { stop(); }

In Outline, select Reset button. Enter the following script :

on(press)
{
   _root.reset();
   gotoSceneandPlay("<current scene>",1);
}

In Outline, select Envoyer button. Enter the following script :

on(press)
{ // variables x...... transmitted to PHP
   xadversaire = adversaire;
   xdate = date1;
   xstyle = style;
   xscores = scores;
    // webpage : matchs.php
   _root.loadVariablesNum("matchs.php",0,'POST');
   gotoSceneandPlay("<current scene>",1);
}

PHP scripts

Using your text editor, enter :

<?
// xadversaire, xdate, xstyle, xscores come from SWF
$data = array();
$data[0] = $_POST['xadversaire'] ;
$data[1] = $_POST['xdate'] ;
$data[2] = $_POST['xstyle'] ;
$data[3] = $_POST['xscores'] ;
// test if all fields have been filled in
$checksum = 0;
for ($i=0; $i<4; $i++)
   if ($data[$i] != "")
   { // // throw away html tags and protect special char
      $data[$i] = AddSlashes(strip_tags($data[$i]));
      $checksum++;
   }
if ( $checksum == 4 )
{    // connexion à la BD
   $hostname = "aaaaaaaaaaaaa" ; // Name mysql server
   $mysqluser = "bbbbbbbbbbbbb" ; // login
   $mysqlpswd = "ccccccccccc" ; // password
   $database = "dddddddddddd" ; // database name
   $diemessage="Connection refusée" ; // Error Message
   @mysql_connect($hostname, $mysqluser, $mysqlpswd) OR $diemessage;
   @mysql_selectdb($database) OR $diemessage;
   // create table named resultats
   $sql = "CREATE TABLE IF NOT EXISTS `resultats` (
   `idresultat` bigint(20) unsigned NOT NULL auto_increment,
   `adversaire` char(80) NOT NULL default '',
   `date` char(20) NOT NULL default '',
   `style` char(80) NOT NULL default '',
   `scores` char(80) NOT NULL default '',
   PRIMARY KEY (`idresultat`)
   ) TYPE=MyISAM COMMENT='table de résultats' AUTO_INCREMENT=1 ;";
   // do the job if table does not exist
   mysql_query( $sql ) ;
   // insert a record
   mysql_query ( "INSERT INTO resultats (adversaire, date, style, scores) VALUES ('$data[0]', '$data[1]', '$data[2]', '$data[3]')" ) ;
   echo '<SCRIPT language="JAVASCRIPT">alert("Table resultats : Job done");</SCRIPT>';
} // fin if checksum
else echo '<SCRIPT language="JAVASCRIPT">alert("Please, fill in all fields!");</SCRIPT>';
?>

Save this file as matchs.php

(same name as in script)
Not very sure messages will display because of the callback from SWF.
( To see and to improve )

Right now, display records from table resultats.
It's pretty simple but it works. Give it your own styles.

Using your text editor, enter :

<?
function affiche_resultats()
{
   //---------- connexion à la BD ---------------------------
   $hostname = "aaaaaaaaaaa" ; // mysql server Name
   $mysqluser = "bbbbbbbbbb" ; // login
   $mysqlpswd = "ccccccccc" ; // password
   $database = "dddddddddd" ; // Database Name
   $diemessage = "Connection refusée" ; // Error Message
   @mysql_connect($hostname, $mysqluser, $mysqlpswd) OR $diemessage;
   @mysql_selectdb($database) OR $diemessage;
   //--------- throw query to get the records ------------
   $req = "SELECT * FROM resultats";
   $result = mysql_query($req);
   $total = mysql_num_rows($result);
   for ($j=0; $j < $total; $j++)
   {
       $row = mysql_fetch_array( $result ); // get a record
       echo "<TR><TD>".stripslashes($row['adversaire'])."</TD>
      <TD>".stripslashes($row['date'])."</TD>
      <TD>".stripslashes($row['style'])."</TD>
      <TD>".stripslashes($row['scores'])."</TD></TR>\n";
   }
}
?>
<html> <head> </head>
<body>
<TABLE border="2">
<TR><TD>Adversaire</TD><TD>Date</TD><TD>Style</TD><TD>Scores</TD></TR>
<? affiche_resultats(); ?>
</TABLE>
</body> </html>

Save it as affiche.php. That's all !

 


Si vous aimez le site

 

Select a language if you need :


Page chargée en 0.022 sec.

Dernière Modification : Mer 25 Janvier 2017 8:56
Copyright © 1999-2017 Jean-Paul Molina Tous droits réservés.

to Google