Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-11-2005, 05:59 PM   #1
antonmills
Registered User
 
Join Date: Feb 2005
Location: Cardiff, UK
Posts: 29
Default AS2, PHP and mySQL login script

Hey all, been working on a flash based website that will have a login system.

I need for the flash interface to pass two variables to my PHP script (username and password). The PHP script will connect to my mySQL database and see if there there is a match, if so the PHP script will return a value to flash in order to allow access. Sounds pretty straightforward but as its my first attempt at all this i'm having some problems and hopefully the experts on this board might be able to give me a hand.

Ill try to explain everything as indepth as I can.

I have the mySQL database up and running and I've put together a php script that queries the database (ive tested the script by creating a html form and it works as expected by letting me know if the username and password is correct) however im not sure how the script should be altered for use by flash instead of html. the script so far is:

PHP Code:
<?php
//My login Script
// declare variables
$username=$_POST['uname'];
$password=$_POST['passw'];
//
// mysql connection variables
$host '*****';
$dbuser '*****';
$dbpass '*****';
$dbname '*****';
$table '*****';
//
// connect to db
$db = @mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
$db mysql_select_db($dbname);
if(!
$db)
{
print 
"error=could not connect to $dbname table";
exit;
}
//
// check table
$query mysql_query("SELECT * FROM $table WHERE USERname = '$username' AND USERpass = '$password'");
$num mysql_num_rows($query);
if(
$num>0)
{
    print 
"user=ok";
    
} else {
    print 
"error=not ok";
}
?>
like I said this works fine with a html form and the variables sent through POST. I have two text fields declared in flash and a submit button, Ive created the following AS2 code for the login:

Code:
var submit:Button = Button(submitbtn);
var uname:TextField = TextField(uname);
var passw:TextField = TextField(passw);
var msgbox:TextField = TextField(msg);
//
submit.onRelease = function() {
	//call php to verify the correct username and password
	var myVars:LoadVars = new LoadVars();
	myVars.uname = uname.text;
	myVars.passw = passw.text;
	myVars.sendAndLoad("login.php", myVars, 'POST');
	myVars.onLoad = function(success) {
		if (success) {
			msgbox.text = "yup";
		} else {
			msgbox.text = "nope";
		}
	};
};
stop();
The error im getting is that the script constantly prints out "nope" to messagebox indicating its not loading the login.php script. Ive tried using full path names to the login script and the login script is in the same directory as the php file on the server.

Any help is muchly appreciated
Thanks in advance

Ant
antonmills is offline   Reply With Quote
Old 11-11-2005, 06:06 PM   #2
Cota
Super Moderator
 
Cota's Avatar
 
Join Date: Jul 2001
Location: NYC
Posts: 10,175
Default

I'm not much of a PHP guy, but thing is you should use echo instead of print.
print "user=ok"; should be, echo "&user=ok"

also
ActionScript Code:
submit.onRelease = function() {     //call php to verify the correct username and password     var myVars:LoadVars = new LoadVars();     myVars.uname = uname.text;     myVars.passw = passw.text;     myVars.onLoad = function(success) {         if (success) {             msgbox.text = "yup";         } else {             msgbox.text = "nope";         }     };              myVars.sendAndLoad("login.php", myVars, 'POST'); };
__________________
Color Wars™ | (kul′ər wôrs) n. - Open conflict between factions. www.theColorWars.com

cota - www.chadworkman.com | http://shavedplatypus.com
occupation: designer | flash developer | server-side developer (php, asp, mssql, mysql)
Cota is offline   Reply With Quote
Old 11-11-2005, 06:24 PM   #3
antonmills
Registered User
 
Join Date: Feb 2005
Location: Cardiff, UK
Posts: 29
Default

Thanks for the feedback, ill change the prints to echo and see what happens.

Ive just tested my old scripts on a friends hosting and it seems to work fine, guessing the error was something to do with my hosting package (brinkster.com).

Ant
antonmills is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:28 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.