A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Log In script :: CS5/AS2/PHP Please help

  1. #1
    Member
    Join Date
    Aug 2006
    Location
    Orange County, Calif
    Posts
    32

    Log In script :: CS5/AS2/PHP Please help

    I would really appreciate some help with my script.
    My flash login form is not passing the variables to my
    php script.
    I have a log in form:

    - email field: instance name = e_mail / variable = email
    - password field: instance name = pw / variable = pass
    - error meggase field : variable = error_msg

    My AS looks like this:
    Code:
    stop();
    /------------------------------------------	
    logbtn.onRelease = function() {
    	if (e_mail.length<1) {
    		error_msg = "Introducir Correo";
    		}
    		else if (pw.length<1) {
    			error_msg = "Introducir Contraseña";
    			}
    			
    		loadVariablesNum("login2.php", 0, "POST");
    			
    }
    My php code looks like this:
    PHP Code:
    <?php
    require("include/dbconnect2.php");

    $e_mail $_POST['email'];
    $pw =  $_POST['pass']; //retreive the variables from flash.

    $result mysql_query("SELECT email, pass FROM registration  ");
      
    $row mysql_fetch_array($result);
      
    $f_email=$row['email'];
      
    $f_pass=$row['pass'];

     if(
    $e_mail == $f_email && $pw == $f_pass)
     { 
      echo 
    "&error_msg=Loging Successful."
     }
     
     else {
         echo 
    "&error_msg=Login Failed";
        
     }
    ?>
    The php script works itself, if i set the variables like
    PHP Code:
    $e_mail 'user@email.com'//dummy user email i put in my db
    $pw '123456';


    $result mysql_query("SELECT email, pass FROM registration  ");
      
    $row mysql_fetch_array($result);
      
    $f_email=$row['email'];
      
    $f_pass=$row['pass'];

     if(
    $e_mail == $f_email && $pw == $f_pass)
     { 
      echo 
    "Loging Successful."
     } 
    It works, but when passing the variables from flash is not working. Instead, on my error_msg i get the echo from php "Login Failed" even i enter the correct user email and password that i entered in my DB.
    Yes, I know I'm able to conect to my db successfully so it's not a db connection problem.

    I created a registration form and i pass the variables to my register.php with no problems and user gets put into my db. so im not sure why it doesnt pass variables to php when trying to log in.

    Any ideas what I'm doing wrong in flash?

    PS: i know i should use
    PHP Code:
    ('SELECT * FROM registration WHERE email =$email, AND pass=$pw); 
    but i get a mysql error.

    I appreciate any help in advanced. Thanks
    Sek Loso is rock n roll

  2. #2
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    Actionscript Code:
    logbtn.onRelease = function() {
        var loginResponse:LoadVars = new LoadVars();
        loginResponse.onLoad = function(success:Boolean) {
            if (success) {
                result_txt.text = this.result;
            } else {
                result_txt.text = "Error: Unable loading";
            }
        };
        var login:LoadVars = new LoadVars();
        login.email = email_txt.text;
        login.pass = pass_txt.text;
        login.sendAndLoad("login.php",loginResponse,"POST");
    };


    arkitx

  3. #3
    Member
    Join Date
    Aug 2006
    Location
    Orange County, Calif
    Posts
    32
    Quote Originally Posted by arkitx View Post
    Actionscript Code:
    logbtn.onRelease = function() {
        var loginResponse:LoadVars = new LoadVars();
        loginResponse.onLoad = function(success:Boolean) {
            if (success) {
                result_txt.text = this.result;
            } else {
                result_txt.text = "Error: Unable loading";
            }
        };
        var login:LoadVars = new LoadVars();
        login.email = email_txt.text;
        login.pass = pass_txt.text;
        login.sendAndLoad("login.php",loginResponse,"POST");
    };


    arkitx
    Hello and thanks for the help. I've implemened your code
    changed my variables on my fla file to match the ones on your code so now my variables are:

    email field : variable name - email_txt
    pass field : variable name - pass_text
    error message field : instance name - result_txt

    A.S.
    Actionscript Code:
    stop();
    logbtn.onRelease = function() {
        var loginResponse:LoadVars = new LoadVars();
        loginResponse.onLoad = function(success:Boolean) {
            if (success) {
               
               result_txt.text = this.result;
         } else {
                result_txt.text = "Error: Unable loading";
            }
        };
        var login:LoadVars = new LoadVars();
        login.email = email_txt.text;
        login.pass = pass_txt.text;
        login.sendAndLoad("login2.php",loginResponse,"POST");
    };

    I have also updated my php file:
    PHP Code:
    <?php
    require("include/dbconnect2.php");

    $e_mail $_POST['email']; //Using Method 'GET' to
    $pw =  $_POST['pass']; //retreive the variables from flash.

    //Query the database for the user AND pass combination to check if it exists
    $result mysql_query("SELECT email, pass FROM registration  ");
    //if the rows return from the query equal to 0 (no sch combination of user/pass)

      //If a combination was found set the user/pass variables as the ones in the db
      
    $row mysql_fetch_array($result);
      
    $f_email=$row['email'];
      
    $f_pass=$row['pass'];

     if(
    $e_mail == $f_email && $pw == $f_pass)
     { 
      echo 
    "&result=Loging Successful"//Send flash the sucess passage along with userpass
     
    }
     
     else {
         echo 
    "&result=Login Failed.";
        
     }
    ?>
    Now when I click the log in button, i get the Login Failed.";
    error message on my result_txt field it even shows the .";
    I get this Login Failed."; error even I input the correct email
    and pass that i manually entered on my db.
    I'm still new on AS.
    Or is my logic on php wrong? I mean the way im trying to
    query for the data on my db? As i interpret it i dont think it makes much difference if i use the method i'm using currently or if i use the
    PHP Code:
    (SELECT FROM registration WHERE email='$email' AND pass='$pass'); 
    Or does it make any difference?

    I would appreciate any further suggestions. Thanks again for all the help.
    Sek Loso is rock n roll

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    you could temporarily replace the sendAndLoad("url",loginResponse,"POST")
    by send("url","_blank","POST")
    to open a new window. This way you can echo stuff or even var_dump the mysql result.

    Unless there really is just one login (admin type), the php looks quite wrong.
    You should either use the "select ... where" or loop over the results

    Musicman

  5. #5
    Member
    Join Date
    Aug 2006
    Location
    Orange County, Calif
    Posts
    32
    Quote Originally Posted by Musicman View Post
    Hi,

    you could temporarily replace the sendAndLoad("url",loginResponse,"POST")
    by send("url","_blank","POST")
    to open a new window. This way you can echo stuff or even var_dump the mysql result.

    Unless there really is just one login (admin type), the php looks quite wrong.
    You should either use the "select ... where" or loop over the results

    Musicman
    Thanks for the reply, I'm a newbie in flash php, i'll try the select from where again, tho the first time i got an error message, but i'll double check maybe i misspelled something. also i'll try the send("url _blank","POST")
    Thanks for the help
    Sek Loso is rock n roll

  6. #6
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    Your PHP should look like this

    Actionscript Code:
    <?PHP
    $host="localhost";
    $dbuser = "root";
    $dbpass = "";
    $dbname = "napoloso";
    $table = "usersLogin";

    $user=$_POST["email"];
    $pass=$_POST["pass"];

    if($user && $pass){
        mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
        mysql_select_db($dbname);
        $query = mysql_query("SELECT * FROM $table WHERE username = '$user' AND password = md5('$pass')");
        $num = mysql_num_rows($query);
        if($num==1){
        echo "&result=OK";    
        } else {
        echo "&result=Error";
        }
    }
    ?>

    Note: Your password should md5 encrypted. And check all the parameters with MySQL settings.





    arkitx
    Last edited by arkitx; 02-15-2012 at 03:47 PM.

  7. #7
    Member
    Join Date
    Aug 2006
    Location
    Orange County, Calif
    Posts
    32
    Quote Originally Posted by arkitx View Post
    Your PHP should look like this

    Actionscript Code:
    <?PHP
    $host="localhost";
    $dbuser = "root";
    $dbpass = "";
    $dbname = "napoloso";
    $table = "usersLogin";

    $user=$_POST["email"];
    $pass=$_POST["pass"];

    if($user && $pass){
        mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
        mysql_select_db($dbname);
        $query = mysql_query("SELECT * FROM $table WHERE username = '$user' AND password = md5('$pass')");
        $num = mysql_num_rows($query);
        if($num==1){
        echo "&result=OK";    
        } else {
        echo "&result=Error";
        }
    }
    ?>

    Note: Your password should md5 encrypted. And check all the parameters with MySQL settings.





    arkitx
    Thank you very much , that helps a lot. I wasn't using the md5 encryption on my
    PHP Code:
    $query mysql_query("SELECT * FROM $table WHERE......"); 
    line so it was giving me an sql error, as in all the tuts i've seen on the web didnt mention anything about md5 on that line, adding that md5 solved the error messges i was getting. also added the md5 encryption on my register page and now i get reply from php, even if i input the correct user and pass i get the "error" from php which is still better cause i wasn't even getting a reply from php in flash. i'll check my sql settings and see if i can get it to work.

    again thanks for all the help.
    Sek Loso is rock n roll

  8. #8
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    You database password section should look like this by md5 encryption.




    arkitx
    Last edited by arkitx; 02-18-2012 at 09:08 AM.

  9. #9
    Member
    Join Date
    Aug 2006
    Location
    Orange County, Calif
    Posts
    32
    Quote Originally Posted by arkitx View Post
    You database password section should look like this by md5 encryption.


    arkitx
    thanks thats how my passwords look after i added the md5 encryption but still
    it returns an error im reading the mysql manual and see if i can figure out why. thanks a lot for the help
    Sek Loso is rock n roll

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center