# ActionScript PHP MySQL problem

**URL:** <https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886>\
**Category:** flash\
**Created:** [September 1, 2003, 3:12pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886 "2003-09-01T15:12:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nevermore](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@Nevermore](https://forum.kirupa.com/u/Nevermore)\
**Post date:** [September 1, 2003, 3:12pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/1 "2003-09-01T15:12:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:36pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/2 "2003-09-01T15:36:58Z")

</div>

Welcome to the forums =)

Is this of any help ? [http://www.kirupa.com/web/sqlrecords\_php.htm](http://www.kirupa.com/web/sqlrecords_php.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:38pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/3 "2003-09-01T15:38:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:46pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/4 "2003-09-01T15:46:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:48pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/5 "2003-09-01T15:48:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:50pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/6 "2003-09-01T15:50:55Z")

</div>

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:

```php

$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:

```auto

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? 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:52pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/7 "2003-09-01T15:52:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:55pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/8 "2003-09-01T15:55:09Z")

</div>

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

And welcome to our humble community btw :beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:59pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/9 "2003-09-01T15:59:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 4:00pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/10 "2003-09-01T16:00:02Z")

</div>

> 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 🙂 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 4:02pm UTC](https://forum.kirupa.com/t/actionscript-php-mysql-problem/29886/11 "2003-09-01T16:02:44Z")

</div>

> \*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](http://www.kirupaforum.com/forums/showthread.php?threadid=17604&highlight)
