Adam made a good suggestion - but using LoadVars is better, and if you are retrieving text it's easier to bring it back as an xml file, otherwise an ampersand stops you cold. Here's my call to the login script to authenticate users for a news site when the login button is clicked.

The varSender and varReceiver are recommended by Colin Moock to avoid caching. His "ActionScript for Flash MX The Definitive Guide", O'Reilly, ISBN 0-596-00396-X is worth every penny. Also visit
Values in first_txt.text, last_txt.text, and pass_txt.text come from those text boxes.

The variable "host" is retrieved from a file in the first frame of the movie.

ckval is stored in a shared object so that subsequent logins are automatic.
autologin = true is the key which unlocks the rest of the movie
read is the frame where another script loads the day's news stories, also stored in a MySQL database.
frame 7 is for login failed - when I added it I had no space to name it.

So, what does the php script return? Exactly this, with no leading space or empty line, and on one line:

(I was tearing my hair out - everything looked RIGHT, yet the movie kept failing, dumbly. Then I realized there was a blank like ahead of the returned values. Removed it and magic happened.)

Flash is alternately exasperating and wonderful.

HTH - Miles

----------- flash code calling PHP script ----
function onLogin(){
if(first_txt.length > 0 && last_txt.length > 0 && pass_txt.length > 0)
varSender = new LoadVars();
varReceiver = new LoadVars();
varSender.first_name = first_txt.text;
varSender.last_name = last_txt.text;
varSender.password = pass_txt.text;
varSender.action = 'login';
varSender.sendAndLoad("http://"+ host + "user_logon.php", varReceiver, 'GET');
varReceiver.onLoad = function()
if(!this.error && this.CkVal != ""){ = this.CkVal;
if(!this.error && this.ValidLogin == "true") {
_root.ValidLogin = this.ValidLogin;
} else {
first_txt.selectable = true;
last_txt.selectable = true;
pass_txt.selectable = true;
loginButton.enabled = true;
} //end of function onLogin
------------ end of Flash code -------

At 05:15 PM 6/25/2003 +0200, Ron Allen wrote:
Does anybody have an idea how-to use Flash and PHP to access a MySql
database. I know how to use PHP and mysql with no problem to pull info, but
with Flash I am struggling.

PHP Database Mailing List (
To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to