PDA

View Full Version : Flash sendAndLoad to MySQL PHP problem


griffles
04-26-2006, 03:49 PM
Hi all that reads this

I am having a nightmare integrating my flash front end program with a mySQL database. All I need for it to do is query the database for a username and then send a string back to flash. I have hard coded the php script and can return a string so I know it works fine. The php script looks like this:


<?php
mysql_connect("database","username","password");
mysql_select_db("contact");

$tab = $_POST['login'];
$qr = mysql_query("SELECT * FROM users WHERE username = '".$tab."'");

// start output string for flash
$nrows = mysql_num_rows($qr);

if ($nrows == 1) {
$rString= "feedback=Success";
$row = mysql_fetch_array($qr);
$rString .= "&username=".$row['username'];
$rString .= "&firstName=".$row['firstName'];
$rString .= "&credits=".$row['credits'];
}else {
$rString= "feedback=Your username was not found - Please register";
}
echo $rString;
?>


if I run this code with a username that exists in the database in place of $tab there is no problem. The actionscript that is coming from flash is as follows

var c = new LoadVars();
c.onLoad = showContent;
function showContent() {
if (this.feedback == "Success") {
_root.feedback = "You are logged in";
_root.loginUserName = this.username;
_root.firstName = this.firstName;
_root.credits = this.credits;
_root.loggedIn = true;
trace("user name coming from php = "+_root.loginUserName)
gotoAndPlay("success");
}else{
_root.feedback="Username not found, please register";
trace("failure called")
}
}
login_btn.onPress = function() {
_root.feedback = "Logging in, please wait...";
//c.login = _root.userNameText;
c.login = "jules84";
c.sendAndLoad("http://nemesis.bournemouth.ac.uk/~jgriffiths/contact/login.php", c, "POST");
getURL("http://nemesis.bournemouth.ac.uk/~jgriffiths/contact/login.php")
trace(c);
};

if i trace(c) in the output window I get the following.......

login=jules84&onLoad=%5Btype%20Function%5D

I am pretty sure that there is nothing wrong with the actionscipt as it sends a string. (c.login = jules84 (this name is definately in the database) however I believe the problem to be with the following line

$tab = $_POST login

as if I echo $tab in the script I ALWAYS get nothing!!!!!! Is it possible that the $_POST command is not extracting the information from the string?

This is driving me mad and cant find a logical solution anywhere. Please help me out

Griff

i_am_a_lazy_man
04-27-2006, 02:17 PM
You run both the sendAndLoad and getURL to the same php script at the same time? Remove the getURL (as the php script will only recognize $_GET if incoming variables are from the getURL) and try again. If you want to test the return result, you don't have to use getURL to do that. You can trace the "c" content from within the function showContent().

c.sendAndLoad("http://nemesis.bournemouth.ac.uk/~jgriffiths/contact/login.php", c, "POST");
getURL("http://nemesis.bournemouth.ac.uk/~jgriffiths/contact/login.php")

griffles
04-27-2006, 04:08 PM
that was the problem mate, you clearly cannot use the getURL function at the same time......

legend!

quincewyss
05-28-2008, 08:32 AM
Check out Peak Studios Flash PHP MySQl extension for AS2 and AS3. I don't know the exact link but the have it on their home page at http://peakstudios.com

It will make your coding a much happier time!