Jump to content

Login with flash, PHP and mysql


Recommended Posts

If been reading tons of tutorials on this and tried it on multiple ways, but it doesn't seem to be working. Why is that?

Can enybody help me out.

 

This is the script I came out with:

 

 

1. MySQL:

- i've created a table userLogin with 3 colums : id, username, password

 

2. Flash:

I got a very simple form being: 1 button btn_ok, 2 input fields named txt_login and txt_password, 1 dynamic foeld txt_result

In the first frame of scene 1 this script.

 

btn_ok.onRelease = function() {

var myLogin:String = txt_login.text;

var myPassword:String = txt_password.text;

maVariable = new LoadVars();

maVariable.var_login = myLogin;

maVariable.var_password = myPassword;

maVariable.onLoad = function() {

if (maVariable.allow == "1") {

//actions

} else {

txt_result.text = "Login/Password incorrect";

}

};

maVariable.sendAndLoad("login.php", maVariable, "POST");

};

 

 

3. PHP: (login.php)

 

<?php

session_start() ;

 

$login = $_POST["var_login"] ;

$password = md5($_POST["var_password"]);

 

if ( $login != '' && $password != '' )

{

$requete = "SELECT username FROM userLogin WHERE username = '$login' AND password = '$password'" ;

 

$server = "localhost";

$basededonnees = "fa225635" ;

$utilisateur = "******" ;

$mdp = "fa225635_Members" ;

 

$connection = mysql_pconnect($server,$utilisateur, $mdp) ;

$choix_db = mysql_select_db($basededonnees, $connection) ;

$resultat = mysql_query($requete,$connection) ;

mysql_close($connection);

 

$result = mysql_fetch_array( $resultat ) ;

 

if ( $result['username'] == $login )

{ echo 'allow=1' ; }

else

{ echo 'allow=0' ; }

}

else { echo 'allow=0' ; }

?>

 

Link to comment
Share on other sites

Guest Geoff

Try the following configuration below:

 

 

 

 

 

Flash:

 

 

btn_ok.onRelease = onLoginButtonClick;

 

private function onLoginButtonClick(e:Event):void {

 

if (myLogin == "" || myPassword == "")

{

userInvalid();

return;

}

// AS3

// Create a Request Loader

var loader : URLLoader = new URLLoader();

var request : URLRequest = new URLRequest("/verify.php");

 

// pass the post data

request.method = URLRequestMethod.POST;

var variables : URLVariables = new URLVariables();

variables.userName = myLogin;

variables.pwd = myPassword;

request.data = variables;

 

// Add Handlers

loader.addEventListener(Event.COMPLETE, on_complete);

loader.load(request);

}

 

private function on_complete(e : Event):void{

// do your stuff here

var loader:URLLoader = e.target as URLLoader;

var xmlData:XML = new XML(loader.data);

 

if (xmlData.isValidated == "true") {

 

userValidated();

}

else if (xmlData.isValidated == "false") {

userInvalid();

}

 

else

{

displayError();

}

 

}

 

function userValidated():void {

//The user has logged in

}

 

function userInvalid():void {

//wrong password

}

 

function displayError():void {

//an error occured

}

 

 

Verify.php:

 

<isValidated>

<?php

session_start() ;

 

$login = $_POST["userName"] ;

$password = md5($_POST["pwd"]);

 

$requete = "SELECT username FROM userLogin WHERE username ='".$login."'";

 

$server = "localhost";

$basededonnees = "fa225635" ;

$utilisateur = "******" ;

$mdp = "fa225635_Members" ;

 

$connection = mysql_pconnect($server,$utilisateur, $mdp) ;

$choix_db = mysql_select_db($basededonnees, $connection) ;

$resultat = mysql_query($requete,$connection) ;

 

 

$result = mysql_fetch_array( $resultat ) ;

 

if ( $result['password'] == $password )

{

?>

 

true

 

<?php

}

else

{

?>

 

false

 

<?php

}

 

?>

</isValidated>

Link to comment
Share on other sites

The code looks complicated to me, but then again I still don't know a lot of programming.

 

If I enter the code in flash (macromedia) it tells me the code isn't correct.

 

 

 

When I do enter it and try to run the movie it says:

 

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 3: ';' expected

private function onLoginButtonClick(e:Event):void {

 

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 12: ';' expected

var loader : URLLoader = new URLLoader();

Link to comment
Share on other sites

Guest Geoff
The code looks complicated to me, but then again I still don't know a lot of programming.

 

If I enter the code in flash (macromedia) it tells me the code isn't correct.

 

 

 

When I do enter it and try to run the movie it says:

 

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 3: ';' expected

private function onLoginButtonClick(e:Event):void {

 

Scene=Scene 1, Layer=Layer 2, Frame=1: Line 12: ';' expected

var loader : URLLoader = new URLLoader();

 

It might be that you are using an old version of flash: macromedia is now adobe; that tells me your version of flash is old. Ill try testing the code myself.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...