ActionScript PHP MySQL problem

I am making a game which would ask you to login when you play so it can store your progress. That is working fine, and I have the usernames and passwords, plus all the other information stored in a MySQL database. The password protection works fine, but in the next frame I want to load all the information from the database using the username and password entered before. How would I do this?

Welcome to the forums =)

Is this of any help ? http://www.kirupa.com/web/sqlrecords_php.htm

Sorry, I don’t think I made myself clear the first time round. I’m fine with the PHP and SQL, it’s the actionScript I can’t do. I’ve been thinking about my problem and I think I can do it using LoadVars. The problem is that I don’t understand how to use them properly - I can send information but not receive it. Can you help?

Ok.

Use the loadVars object in this way:

carica = new LoadVars(); // create loadVars
carica.load(“file.php”);
carica.onLoad = function(success) {
if(success) {
variable1 = this.variable1;
variable2 = this.variable2;
// for each php variable i assign a variable in Flash
}
else {
// if something wrong do something
}
}

sorry for my english i’m italian, first time in this forum.

Lol, I understood you wrong. Yes, what Syntax posted should do it. Sorry again !

In table_A, you would have

| ID | username | psw |

Let’s say you’re storing a player’s score, you would have this in table_B

| ID | userID | score |

when the user logs on, you would do something like this:


$user = $_POST['user'];
$psw = $_POST['psw'];

$result = mysql_query("select * from table_A where username = '$user'");
while ($userInfo = mysql_fetch_array($result, MYSQL_ASSOC)
{
if ($userInfo['psw'] == $psw) {
$id = $userInfo['ID'];
echo 'status=success';
} else {
echo 'status=logon failed';
}
}
if(isset($id)) {
$result = "select score from table_B where userID = '$id'";
while($score = mysql_fetch_array($result, MYSQL_NUM) echo '&score=' . $score[0];
}

In flash, your actionscript would look something like this:


send_lv = new LoadVars();
load_lv = new LoadVars();
load_lv.onLoad = function (success) {
if ( success ) {
trace (this.status);
trace (this.score);
} else {
trace("error loading script");
}
}
send_lv.user = username_textfield.text;
send_lv.psw = password_textfield.text;
send_lv.send('myscript.php', load_lv , "POST");

does the code about make sense to you or give you an idea? :slight_smile:

remember that you php page has to output data in the correct way, like a .txt file with variables

For example the .php file may have an output like

&variable1=home&email=mymail@mail.com&adress=myaddress

bye

yup… that’s what the echo ‘status=logon failed’; and ‘&score=’ . $score[0]; parts are for :slight_smile:

And welcome to our humble community btw :beam:

Sorry if I’m being stupid, but you seem to have used totally different code. What actionscript code would I use to send the value of a textfield to a php page, wait for it to be processed and then set a variable as the result. I think I understand how to do the PHP so I only need the actionscript. If you just show me how to do it for one variable I can just repeat it for each extra text field.

yup… that’s what the echo ‘status=logon failed’; and ‘&score=’ . $score[0]; parts are for

yes, you posted while i was writing my post, i don’t read it :slight_smile: :slight_smile:

*Originally posted by Nevermore *
**What actionscript code would I use to send the value of a textfield to a php page, wait for it to be processed and then set a variable as the result. **
look at this thread, it explains it…

http://www.kirupaforum.com/forums/showthread.php?threadid=17604&highlight