Display a variable in FLASH using LoadVars and PHP

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

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.

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

my_vars.send(“http://localhost/lms/Login.php",my_vars,"POST”);
replace by
my_vars.sendAndLoad(“http://localhost/lms/Login.php",this,"POST”);
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;
}

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

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