PDA

View Full Version : Problem getting flash to talk to php/mysql



bobwhosmiles
September 20th, 2007, 04:49 PM
Hi,

Am working on a site that needs a user login. Found the tutorial at: http://www.kirupa.com/developer/actionscript/authentication.htm and tried to incorporate it into my site design. If I view the php file in my browser I just get a blank screen.

I tried swapping:


$user=$_POST['user'];
$pass=$_POST['pass'];for

$user = "myuser";
$pass = "mypassword";(ie. values which I know are in the database) When I do this the browser displays the desired results eg "status=You're in&checklog=1"

So it seems the problem is with passing the values from flash to PHP. The ActionScript behind the submit button looks like this:


on (release, keyPress "<Enter>") {
if (userinput.text != "" && passinput.text != "") {
status = "Begin Login Process - Wait...";
loadVariablesNum("newlogin.php", 0, "POST");
}
else status = "Please complete your user name and password before clicking submit";
}I've double checked that the instance name and var values are right in the .fla

Can anyone offer any help please? I'm tearing my hair out after about 2 days trying to make this work!

Cheers

Bob

BradLee
September 20th, 2007, 04:57 PM
EDIT: Yes, I know this is only if the data is not form-encoded (such as XML)

Flash actually sends your post as raw data, so it ends up in the HTTP_RAW_POST_DATA global variable. You can access this variable with the globals array using
$GLOBALS['HTTP_RAW_POST_DATA']

bobwhosmiles
September 20th, 2007, 05:29 PM
Hi Spork,

Thanks but I'm not sure how to incorporate this in my php which currently looks like this:


<?PHP
mysql_pconnect("localhost","user","password") or die ("didn't connect to mysql");
mysql_select_db("customers") or die ("no database");

$user=$_POST['user'];
$pass=$_POST['pass'];
$table = "users";

$query = "SELECT * FROM $table WHERE username = '$user' AND userpassword = '$pass'";
$result = mysql_query( $query ) or die ("didn't query");

$num = mysql_num_rows( $result );
if ($num == 1){
print "status=You're in&checklog=1";
} else {
print "status=Sorry, but your user name and password were not recognised&checklog=2";
}

?>

Moreover, I can't understand why the above won't work with the AS below which is listening for the response from the PHP above.

stop();
userinput.restrict="a-zA-Z0-9";
passinput.restrict="a-zA-Z0-9";
Selection.setFocus(userinput);
status="Enter your information and submit";
this.onEnterFrame = function () {
if(_root.checklog == 1){
_root.gotoAndStop(2);
}
if(_root.checklog == 2){
_root.gotoAndStop(3);
}
}


Any ideas?

Bob

BradLee
September 20th, 2007, 06:12 PM
I'm sorry, I've informed you wrong (mostly). The data flash sends is sometimes left in raw format because it isn't form encoded (like if you were sending XML). It's been a long time since I've sent data to PHP form-encoded so I kinda forgot, sorry. I hope this clears it up.

The PHP you have should work. The problem most likely lies with what you are sending the PHP page. I'm not real familiar with the functionality of loadVariablesNum so gimme a minute and I'll try and figure this out...

Sorry for the confusion.

BradLee
September 20th, 2007, 06:27 PM
I think your problem might be that you are calling loadVariablesNum from inside your submit button, but your input boxes are stored outside in the parent movieclip.

You might try doing something like this:



_parent.loadVariables("newlogin.php", "POST");


or



_root.loadVariables("newlogin.php", "POST");


Depending on what movieclip your form objects are stored in.

There is also a tutorial here on kirupa that might help:
http://www.kirupa.com/developer/actionscript/flash_php_email.htm (http://www.kirupa.com/forum/../developer/actionscript/flash_php_email.htm)

Hope that helps!

bobwhosmiles
September 20th, 2007, 07:19 PM
thanks but neither of these work. Had a look at the other tutorial you suggested and tried combining the username/password fields in a form and using form.loadVariables("newlogin.php", "POST"); but still got the same problem.

Can anyone make the original tutorial files work? (http://www.kirupa.com/developer/actionscript/code/authenticate.zip)

Any help appreciated

Bob