zorrotwee Posted June 18, 2010 Posted June 18, 2010 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' ; } ?>
Wizard Posted June 18, 2010 Posted June 18, 2010 You could also try asking the MySQL, PHP, and Flash forums.
Guest Geoff Posted June 18, 2010 Posted June 18, 2010 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>
zorrotwee Posted June 19, 2010 Author Posted June 19, 2010 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();
Guest Geoff Posted June 21, 2010 Posted June 21, 2010 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now