Php/ flash...wait for mySQL response?

Hi,
I have made a .swf that sends data to a php file which again retrieve/ validates data in mySQL table ie. username and password.

In case the user is granted access I want the .swf to go to let’s say frame 2 otherwise it should be frame3.

How do I send this ‘action’ to the fla/swf ?
Best regards

…code accessing tables/ database…

//see if there’s an EXACT match (username/ password)
$num = mysql_num_rows( $result_1 );
if ($num == 1){
print “&mess=you have access.”;
// Here I would like to go to frame2 in my fla/swf

} else {

print "&medd=you have no access.";

// Here I would like to go to frame3 in my fla/swf

}

Use an extra variable passed along. Flash can then check that variable and decide what frame to go to.


$num = mysql_num_rows( $result_1 );
if ($num == 1){
print "mess=you have access.&error=0";
// Here I would like to go to frame2 in my fla/swf
} else {
print "medd=you have no access.&error=1";
// Here I would like to go to frame3 in my fla/swf
}

Then in Flash, you can use an if statement to check the value of error and go to frame 2 or 3 :slight_smile:

of course…you are right.

I inserted:

if ( error==‘0’ ) {
gotoandstop(2);
}

but nothing happens ?

I noticed you replaced [font=Courier New][color=#dd0000]&mess [font=Verdana][color=#000000]with [font=Courier New][color=#dd0000]mess [/color][/font]only. When I do that, I get no message in my messagebox.[/color][/font][/color][/font] In another fla I do not have [font=Courier New][color=#dd0000]& [font=Verdana][color=#000000]and it gives me a message (?). The two fla look identical so I do not quite understand it.[/color][/font][/color][/font]

Best regards

That’s probably because you typed mess for the first and medd for the second :stuck_out_tongue:

What’s your entire script ?

Hi,
This is my php (my message box is called medd in the fla:
<?

$db=mysql_connect("…");
mysql_select_db("…",$db);

$query = "SELECT * FROM login_tab WHERE brugernavn = ‘$usrname_fla’ and kodeord=’$psw_fla’ ";
$resultat = mysql_query( $query,$db ) or die (“didn’t query”);

//see if there’s an EXACT match
$num = mysql_num_rows( $resultat );
if ($num == 1){
print “&medd=No access.&indtast_err=1”;

} else {

$sql = "insert into login_tab (fornavn, efternavn, adr,postnr,bynavn,tlf1,email1,brugernavn,kodeord) values ('$fornavn_fla','$efternavn_fla','$adr_fla','$postnr_fla','$by_fla','$tlf_fla','$email_fla','$usrname_fla','$psw_fla')";
$result = mysql_query($sql,$db);  
print "&medd=You have access.&indtast_err=0";

}

?>

AS:

loadVariablesNum(“site2.php”,0, “POST”);//
if ( indtast_err==‘0’ ) {
gotoandstop(2);// new frame
}

You’re most likely using the variable before it has been loaded. To solve this, you can use the onLoad method of the LoadVars object:


lv = new LoadVars();
 lv.onLoad = function(ok) {
     if (ok) {
         if (Number(this.indtast_err)) {
             trace("You do not have access !");
         } else {
             trace("You have access.");
         }
         trace("PHP Message: "+this.medd);
     } else {
         trace("Could not load data. Check the path.");
     }
 };
 lv.load("site2.php"):
 

Thanks for your reply.
I tried your script and solved the problem but it didn’t quite work with your original suggestion.

I had to use the varible medd from the php to determine what the php result was.
I wrote:
[color=blue]if (medd==‘You do not have access !’)) {[/color]
[color=blue]trace(“You do not have access !”);[/color]
[color=#0000ff]gotoandstop(3);[/color]
[color=blue]} else {[/color]
[color=blue]trace(“You have access.”);[/color]
[color=#0000ff]gotoandstop(2);[/color]
[color=blue]}[/color]
[color=#0000ff][/color]
[color=#0000ff]The reason for rewriting was that no matter what I did, the script executed gotoandstop(3); as well as gotoandstop(2); … and that really does not make any sense to me due to the ‘else’-condition ?[/color]
[color=#0000ff][/color]
[color=#0000ff]I found the result of [/color]color=#000000 [/color][color=#0000ff]was ‘NaN’ … I don’t know what that is ? The way I found it was by setting some inputtext = color=#000000 .[/color][/color]

[color=#0000ff]Setting some inputtext = [/color]color=#000000) [/color][color=#0000ff]gave me the result of e.g. 1 + a space … that is: '1 ’ Why is this the case should it not just be = 1 ? where does the space come from ?[/color]

[color=#0000ff]I can make the script work by using the variable medd as a condition. But only due to the text ([color=#000000]&indtast_err=1":wink: [/color]in the sentence [/color][color=#000000]"&medd=[color=black]You do not have access !&[/color]indtast_err=1";[/color]
[color=#0000ff]Otherwise I would get a space after the varible as '[color=#000000]You do not have access ! '[/color] Just as was the case mentioned above regarding [/color]color=#000000) [/color]
[color=#0000ff][/color]
[color=#0000ff]So your suggestion gave me the result but my final solution is definetly not perfect and I still lack fully understanding of the script.[/color]
[color=#0000ff][/color]
[color=#0000ff]Maybe you could give me some hints since I will be working a lot with these conditiong statements ? But so far thanks for the effort.[/color]
[color=#0000ff][/color]
[color=#0000ff]Best regards[/color]

I just tested it, and it does work. There must be an error in your PHP file not outputting the correct line. The problem here is that the error number received from PHP is NaN, which stands for Not A Number. Are you sure you used the Number() function, as it is necessary to convert the string received to a number ?

Can you show me the exact results of your PHP file alone ?

Hi,
This is my php and AS respectively giving me a few problems:

<?

$db=mysql_connect("…");
mysql_select_db("…",$db);

$query = "SELECT * FROM login_tab WHERE brugernavn = ‘$usrname_fla’ and kodeord=’$psw_fla’ ";
$resultat = mysql_query( $query,$db ) or die (“didn’t query”);

//see if there’s an EXACT match
$num = mysql_num_rows( $resultat );
if ($num == 1){
print “&medd=You do not have access !&indtast_err=1”;
//Reason for no access is the user is to register as new user and here username and pssw is already taken.

} else {

$sql = "insert into login_tab (fornavn, efternavn, email1,brugernavn,kodeord) values ('$fornavn_fla','$efternavn_fla','$email_fla','$usrname_fla','$psw_fla')";
$result = mysql_query($sql,$db); 
print "&medd=You have access.!&indtast_err=0";

// registered as new user…
}

?>

AS:

loadVariablesNum(“reg_hitme2.php”,0, “POST”);// input from inputtext is forwarded php page.

//Now I want to check whether the user was granted access (at the php)
// that is why I need the result (is it possible directly from php to tell what frame to be selected at the fla or do I have to retrieve the result first and then decide what frame is to be selected ?
lv = new LoadVars();
lv.onLoad = function(ok) {
if (ok) {
if (Number(this.indtast_err)) {
trace(“You do not have access !”);
} else {
trace(“You have access.”);
gotoandstop(“indtastning_registreret”);//frame saying: welcome something
}
trace("PHP Message: "+this.medd);
} else {
trace(“Could not load data. Check the path.”);
}
};
lv.load(“reg_hitme2.php”);

}

That’s the PHP file itself, but what’s the result of it ? By the way, the loadVariablesNum is no longer needed, the loadvars takes care of loading it now.

Hi,

Long working hours is the reason for my late reply.

The result is a that the frame gotoandstop(“indtastning_registreret”);
is showed no matter what is reply or result from the sqlstring looking if user is already registered in the table or not.

Is that what you are asking about or ?

Best regards

Hi,
I found a script giving me the result I was looking for:

I keep original script related to the SEND button:
on (release) {
loadVariablesNum(“site2.php”,0, “POST”);
}

The php is the same - no changes made.

Now I have inserted the code below and it works fine. I get the values of the varible without problems:

this.onEnterFrame = function () {
if(_root.indtast_err== 1){
//_root.gotoAndStop(“no_access”);
}
if(_root.indtast_err== 2){
_root.gotoAndStop(“access”);
}
}

If you should have any comments on this I would appreciate your input.
Thanks for your input, I appreciated it. Also it made me look in another usefull direction.

Best regards

No, bad code. The onEnterFrame will keep sending the _root to a specific frame, making it unable to go to any other frame. I’m still wondering why that other code didn’t work, can I see the files ?