Link to home
Start Free TrialLog in
Avatar of Brian Lin
Brian LinFlag for United States of America

asked on

PHP and Flash Q

Hi, Experts:
I made a Flash game that connect to the database ( myAdminSQL, also PHP ) but it is weird the database can only work on Mac's browsers and Windows Netscape, looks like the database does not work or connect on windows IE browser. Is this because somethiing wrong with my script ? or else ?

thanks
Avatar of Billystyx
Billystyx

How do you call the script from flash, and can you post the code for the php (minus your passwords/logins/db name etc)

billystyx
Avatar of Brian Lin

ASKER

ok, let me see....actually, there are many, this one is important -- [ send_lv.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/toy.php", get_lv, "get"); ]--

function checkAnswer(which) {
      selectedAnswer = Number(which["num_txt"].text);
      if (selectedAnswer == solution) {
            disNumber = solution;
            grab.gotoAndPlay("begin");
            gotoAndStop("pass_1");
            _parent._parent.attachGood.attachMovie("youareverygood", "verygoodsign", 299);
            //recording to database
            var send_lv = new LoadVars();
            var get_lv = new LoadVars();
            // Attach some variables to send_vars these will be sent to the server
            trace("toy_chance:"+1);
            send_lv.toy_chance = "1";
            //send_lv.toy_level = "";
            send_lv.id = _global.user_id;
            // Set up an onLoad function to receive variables
            get_lv.onLoad = function() {
                  if (this.checkdone == 1) {
                        gotoAndStop("xxx");
                        _parent._parent.level_mc.unloadMovie();
                  } else {
                        gotoAndStop("xxx");
                  }
                  // end if checkdone
            };
            // Send and load variables from the server
            send_lv.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/toy.php", get_lv, "get");
      } else {
            trace("Wrong");
            _parent._parent.attachBad.attachMovie("tryAgain", "tryAgainSign", 289);
      }
}
also this one ........

//LEVEL CHECK
levelCheck = new LoadVars();
levelCheck.id = _global.user_id;
levelCheck.onLoad = function() {
      if (levelCheck.toy_chance == 0) {
            //attach movie clips
            level_mc.attachMovie("level0", "0", 1);
            toy_mc.toy_inner_clip.gotoAndStop("game_1");
            toy_intro_attach.attachMovie("toy_intro", "ToyIntroductionMovie", 99);
      } else if (levelCheck.toy_chance == 1) {
            //level_mc.attachMovie( "level1", "1", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_2");
      } else if (levelCheck.toy_chance == 2) {
            //level_mc.attachMovie( "level2", "2", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_3");
      } else if (levelCheck.toy_chance == 3) {
            //level_mc.attachMovie( "level3", "3", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_4");
      } else if (levelCheck.toy_chance == 4) {
            //level_mc.attachMovie( "level4", "4", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_5");
      } else if (levelCheck.toy_chance == 5) {
            //level_mc.attachMovie( "level5", "5", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_6");
      } else if (levelCheck.toy_chance == 6) {
            //level_mc.attachMovie( "level6", "6", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_7");
      } else if (levelCheck.toy_chance == 7) {
            //level_mc.attachMovie( "level7", "7", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_8");
      } else if (levelCheck.toy_chance == 8) {
            //level_mc.attachMovie( "level8", "8", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_9");
      }
};
levelCheck.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/check_levels.php", levelCheck, "GET");
If you are sending variables to the server,and the php script is sending variables back, then try using POST instead of GET.

billystyx
oh....let me try it.... but does GET works too ? just not as good as POST
also...does "get" same as " GET " ?
still not working on window....i will post script in Flash and PHP script too....

in the flash.....
// recording to database
var send_lv = new LoadVars();
var get_lv = new LoadVars();
// Attach some variables to send_vars these will be sent to the server
// trace( "carnival_chance:" + 1 );
// trace( "toy_level:" + 1 );
send_lv.carnival_chance = "1";
// send_lv.toy_level = "";
send_lv.id = _global.user_id;
// Set up an onLoad function to receive variables
get_lv.onLoad = function() {
if (this.checkdone == 1) {
gotoAndPlay("pass_1");
_parent._parent.attachGood.attachMovie("youareverygood", "verygoodsign", 299);
_parent._parent.level_mc.unloadMovie();
} else {
gotoAndStop("xxx");
}
// end if checkdone
};
// Send and load variables from the server
send_lv.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/carnival.php", get_lv, "POST");

In the php........
<?php
require( 'db.php' );

//this script updates table math_db WHERE id = $_GET[id]

$carnival_chance = $_GET['carnival_chance'];//this grabs the posted variable character from flash
//$carnival_level = $_GET['carnival_level'];//this grabs the posted variable character from flash
$user_id = $_GET['id'];

$sql = "UPDATE math_db SET carnival_chance = '$carnival_chance'  WHERE id = '$user_id'";
if  (mysql_query($sql)) {
      echo "&checkdone=1";
}
/*
$sql = "UPDATE math_db SET carnival_chance = '$carnival_chance', carnival_level = '$carnival_level'  WHERE id = '$user_id'";
if  (mysql_query($sql)) {
      echo "&checkdone=1";
}
*/
/*

$query="SELECT * FROM math_db WHERE characters = '$n'";
$result=mysql_query($query);
$nr=0;
$nrows=mysql_num_rows($result);
while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
$name[$nr]=($row['characters']);
$finallist=$finallist."&nameA".$nr."=".$name[$nr];
$n++;
}
$finallist=$finallist."&nrows=".$nrows."&checkdone=1&";
print($finallist);
// Check number of rows returned
      if ( mysql_num_rows( $result ) > 0 ) {
            $message .= "&Status=Success recording Complete&CheckLog=1";
      } else {
            $message .= "&Status=Failure - Your guide was not recorded - Please try again";
      }
      
      echo $message;


*/

?>
and this is the database connect php code...change name and IP to  xxx ......

<?php
      mysql_pconnect( "xxx.xxx.xx.xxx", "xxx", "xxx" ) or die ( "Unable to connect to database!" );  
      mysql_select_db( "xxx" );
?>
any comments ? :)
If you are using post in your flash script, you probably need to use post to collect the variables in the php too, like:

$_POST['yourvars'];

try this - past that I am not sure - I will try to look into it today:)

billystyx
Also, can you post a link to the game on the web so I can take a look at that?
let me send you the files...to your email address, so you can look them all
Ok, please check the mail box, thanks :)
Thanks - I meant a link to the site where the game is. But I will take a look tonight at the flas etc. If you can upload them for others to check it might be best:)
actually, other games are the same scripting... with the almost same php and script in the flash
http://www.brianlinstudio.com/learningNetwork

In this link, do you go to carnival and enter you name, and this is where the php script comes in?

If so, what should it do? I am using IE and it seems to log in OK.

billystyx
Hi, billystyx
sorry did reply sooner, I set a log in name for you, go to the http://www.brianlinstudio.com/learningNetwork/kidarea and use "billystyx" to log in... then choose a guide, then choose top city only ( only that works )....in the town, click on the carnival game.... shoot some round, on the buttom, they should show what round you are playing, and when you click on back botton and back to town and re enter to carnival again, the game should start the last round you played...... so, now, the problem is game always start at very beginning and did not go to the last game user left..... mm, i explain well :) .... you can also try the Netscape to see the difference ! thanks

should said,... mm, i hope I explain well :)
Yes, I tried all that, it works fine in netscape (4.7), mozilla and Internet Explorer. I am not sure where the problem is.
On the first (I tested in mozilla) I went to the game and played to level3.
Then when I opened netscape and did the same it took me to level 3 straight away.
Then I went into IE and did the same (each one after logging out), and it took me to level3.

billystyx
yes, but please try to play first at IE only , play 2 or 3 rounds, then come out to the " town " then back into the game again.... shoudl see the problem
no, i left on level 2 and it took me back (I selectred the back button and then clicked on the carnival again) and it returned me to level 2.

really...mm....
out of interest, where does id get set, and how?
Here is how....
      
var send_lv = new LoadVars();
      var get_lv = new LoadVars();
      // Attach some variables to send_vars these will be sent to the server
      send_lv.user_name = Name;
      // Set up an onLoad function to receive variables
      get_lv.onLoad = function() {
            if (this.CheckLog == 1) {
                  //set global variable for user_id
                  _global.user_id = this.id;
                  _global.character = this.character;
                  if (this.character<>"") {
                        gotoAndStop("mathtown2");
                  } else {
                        gotoAndStop("characters");
                  }
            } else {
                  gotoAndStop("name_entry");
                  Status = this.Status;
            }
            // need to add skip for second time log in user, already with character in db
            trace("receiving variables");
            for (p in this) {
                  trace(p+":"+this[p]);
            }
      };
      // Send and load variables from the server
      send_lv.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/Login.php", get_lv, "GET");
so its not a cookie thing?
no... actually, i try to record the screen shoot from my computer.... take a look... 1.7 mb total size..... http://www.brianlinstudio.com/question/Capture.avi
and it is weird, looks like when I log out and re log in, database has the record and game start at last I played..... but it just does not show record or start last game played while at game
I can't view that:(
ok, I try a few time and I found that when I playing any game, the record did reocrd to the database. That is why when user re log in, game would start from last game played.... The problem is while in the game and user play from round 0 to 2, then back to town then re enter game.....there is script that will GET the information from database and should re direct the game to the last round played, so in this case, should direct to round 2.... i guess that script is not working.... and I did not show that script ... so, i will post below ...

**** For example, for the Carnival game... if the databse's carnival row shows = 2 then the following script should direct game to Part_3..... and in Windows IE, it is not working

//LEVEL CHECK
levelCheck = new LoadVars();
levelCheck.id = _global.user_id;
levelCheck.onLoad = function() {
      if (levelCheck.carnival_chance == 0) {
            carnival_mc.scorekeeper.gotoAndStop("part_1");
      } else if (levelCheck.carnival_chance == 1) {
            carnival_mc.scorekeeper.gotoAndStop("part_2");
      } else if (levelCheck.carnival_chance == 2) {
            carnival_mc.scorekeeper.gotoAndStop("part_3");
      } else if (levelCheck.carnival_chance == 3) {
            carnival_mc.scorekeeper.gotoAndStop("part_4");
      } else if (levelCheck.carnival_chance == 4) {
            carnival_mc.scorekeeper.gotoAndStop("part_5");
      } else if (levelCheck.carnival_chance == 5) {
            carnival_mc.scorekeeper.gotoAndStop("part_6");
      } else if (levelCheck.carnival_chance == 6) {
            carnival_mc.scorekeeper.gotoAndStop("part_7");
      } else if (levelCheck.carnival_chance == 7) {
            carnival_mc.scorekeeper.gotoAndStop("part_8");
      } else if (levelCheck.carnival_chance == 8) {
            carnival_mc.scorekeeper.gotoAndStop("part_9");
      }
};
levelCheck.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/check_levels.php", levelCheck, "GET");

**** The following script is from check_level.php....

<?php
require( 'dB.php' );
//this script updates table math_db WHERE id = $_GET[id]
$user_id = $_GET['id'];
$sql = "SELECT toy_chance, carnival_chance, zoo_chance FROM math_db WHERE id = '$user_id'";
$query_result = mysql_query($sql);
$row = mysql_fetch_array($query_result);
echo "&toy_chance=$row[toy_chance]&zoo_chance=$row[zoo_chance]&carnival_chance=$row[carnival_chance]&";
?>
ASKER CERTIFIED SOLUTION
Avatar of Billystyx
Billystyx

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh, only on the PC's IE
Hi
I wonder are there any way to re write the check_levels.php script.... same meaning but other way to write it...
======== Script in check_levels.php ========
<?php
require( 'db.php' );
//this script updates table math_db WHERE id = $_GET[id]
$user_id = $_GET['id'];
$sql = "SELECT toy_chance, carnival_chance, zoo_chance FROM math_db WHERE id = '$user_id'";
$query_result = mysql_query($sql);
$row = mysql_fetch_array($query_result);
echo"&toy_chance=$row[toy_chance]&zoo_chance=$row[zoo_chance]&carnival_chance=$row[carnival_chance]&";
?>
======== Script in Flash ========
//LEVEL CHECK
levelCheck = new LoadVars();
levelCheck.id = _global.user_id;
levelCheck.onLoad = function() {
      if (levelCheck.toy_chance == 0) {
            //attach movie clips
            level_mc.attachMovie("level0", "0", 1);
            toy_mc.toy_inner_clip.gotoAndStop("game_1");
            toy_intro_attach.attachMovie("toy_intro", "ToyIntroductionMovie", 99);
      } else if (levelCheck.toy_chance == 1) {
            //level_mc.attachMovie( "level1", "1", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_2");
      } else if (levelCheck.toy_chance == 2) {
            //level_mc.attachMovie( "level2", "2", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_3");
      } else if (levelCheck.toy_chance == 3) {
            //level_mc.attachMovie( "level3", "3", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_4");
      } else if (levelCheck.toy_chance == 4) {
            //level_mc.attachMovie( "level4", "4", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_5");
      } else if (levelCheck.toy_chance == 5) {
            //level_mc.attachMovie( "level5", "5", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_6");
      } else if (levelCheck.toy_chance == 6) {
            //level_mc.attachMovie( "level6", "6", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_7");
      } else if (levelCheck.toy_chance == 7) {
            //level_mc.attachMovie( "level7", "7", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_8");
      } else if (levelCheck.toy_chance == 8) {
            //level_mc.attachMovie( "level8", "8", 1 );
            toy_mc.toy_inner_clip.gotoAndStop("game_9");
      }
};
levelCheck.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/check_levels.php", levelCheck, "GET");
one more Q....  Can I use levelCheck.sendAndLoad("http://www.brianlinstudio.com/learningNetwork/check_levels.php", levelCheck, "GET"); or should I use levelCheck.sendAndLoad("check_levels.php", levelCheck, "GET"); ?
Second question:There shouldn't be a difference if both the php doc and the html page holding the swf are in the same directory on your server.
And for the first question, you can use POST instead of get, in the flash and in the php, and in the flash your onload function could use a switch statement instead of multiple if-elseif statements, which will make the code cleaner, but won't necessarily change the results.

billystyx