# Display a variable in FLASH using LoadVars and PHP

**URL:** <https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286>\
**Category:** flash\
**Created:** [February 7, 2004, 9:01am UTC](https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286 "2004-02-07T09:01:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jajoho](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@jajoho](https://forum.kirupa.com/u/jajoho)\
**Post date:** [February 7, 2004, 9:01am UTC](https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286/1 "2004-02-07T09:01:59Z")

</div>

What I’m trying to do:

Send a user input to PHP  
Use this input to query a MySQL DB (This works fine)

Get the result back to Flash and put it in a dynamic Text Box - How???

The communication from Flash to PHP works fine. The variable I pass from Flash to PHP are used in the query as intended.

Then Im trying to send a variable back to flash. I cant display this variable in Flash, only in a new explorer window…

\<?php

require ‘Include.php’; //Data about $DBhost,$DBuser,$DBpass  
$user=$\_GET[‘name’];

// Connects to the database.  
mysql\_connect($DBhost,$DBuser,$DBpass);  
mysql\_select\_db("$DBName");

// The SQL query.  
$query = “SELECT \* FROM $table WHERE user =’$user’” ;  
$result = mysql\_query($query);

/\* This just gets the number of rows in the Query \*/  
$numR = mysql\_num\_rows($result);

// If the number of rows is 0–\> no hits on query  
if ($numR\>0) {  
for($i=0; $i \< $numR; $i++) {  
$row = mysql\_fetch\_array($result);  
print $row[‘fname’]; //This prints ‘Bruno’ when user = ‘test’  
}  
}  
else {  
print "not connected ";  
}  
?\>

* * *

Actionsript:

on (release) {  
var my\_vars = new LoadVars();  
//Get the text from Input Text  
my\_vars.name=userName.text;

```
//Send input (my_vars) to PHP and assign result to my_vars
my_vars.send("http://localhost/lms/Login.php",my_vars,"POST");

//Set the result in Dynamic Text box with Var name status
status=my_vars.name;

```

}

* * *

I’ve read all the tutorials I was able to find, looked at the macromedia site, and still not able to solve it.

This problem has been driving me crazy for one week now. I scanned through this forum, but haven’t found anything useful for my case.

Hoping for replies, best regards  
Jarle

---

<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:** [February 7, 2004, 9:05am UTC](https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286/2 "2004-02-07T09:05:15Z")

</div>

coz you are using send, which only sends, but does not expect a result back…  
use sendAndLoad

edit of title as does not include reference to what you use.

---

<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:** [February 7, 2004, 9:06am UTC](https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286/3 "2004-02-07T09:06:31Z")

</div>

I’ve tried sendAndLoad and it still doesn’t work

---

<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:** [February 7, 2004, 9:16am UTC](https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286/4 "2004-02-07T09:16:29Z")

</div>

my\_vars.send(“[http://localhost/lms/Login.php",my\_vars,"POST](http://localhost/lms/Login.php%22,my_vars,%22POST)”);  
replace by  
my\_vars.sendAndLoad(“[http://localhost/lms/Login.php",this,"POST](http://localhost/lms/Login.php%22,this,%22POST)”);  
and you are setting  
status=my\_vars.name;  
before the result comes back, so it’s normal it’s empty…  
check the usage of LoadVars in the AS dictionnary:  
-declare LV object  
-add data  
-set onLoad handler (incl. error checking)  
-send/andLoad  
means: my\_vars.onLoad = function(){  
//check errors here!  
status=this.name;  
}

---

<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:** [February 7, 2004, 9:20am UTC](https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286/5 "2004-02-07T09:20:53Z")

</div>

OK, thanks. I’ll try that  
If it works, you’ll save my weekend 🙂

---

<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:** [February 7, 2004, 9:26am UTC](https://forum.kirupa.com/t/display-a-variable-in-flash-using-loadvars-and-php/42286/6 "2004-02-07T09:26:24Z")

</div>

nice weekend then…  
full example is, i htink, in the sticky in “server side” forum  
(on how to use loadVars + PHP)
