Welcome, Guest
  • Author Topic: user login with mysql  (Read 2580 times)

    mikedhane

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Email
    user login with mysql
    « on: 12/09/08, 17:44 »
    Ok this will be a very long Post

    I hope to help other as well.

    I have my flash 8 file that has frames labeled for user auth.

    Action Scrip is 2.0

    My php

    config.php 
    functions.php
    user.php

    I am not getting data to the mysql.

    and returning member is logged in frame with any user input.

    HELP

    config.php file with out my login :)  sorry  my eyes only


    Code: [Select]
    <?php
        
    // no cache
       
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
       
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
       
    header("Cache-Control: no-store, no-cache, must-revalidate");
       
    header("Cache-Control: post-check=0, pre-check=0"false);
       
    header("Pragma: no-cache");
       
    // displays only errors
       
    error_reporting(E_ERROR);
       
    // mysql connection variables
       
    $host 'mysql4.000webhost.com';
       
    $dbuser 'my_user';
       
    $dbpass 'my_password';
       
    $dbname 'my_name';
       
    $table 'tutorial_user';
       
    // 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;
       }
    ?>
     


    here is the <b>Functions.php</b> file

           
    Code: [Select]
    <?php
    function valid_email($email){
       
    // check if email is valid
       
    if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"
       
    ."@([a-z0-9]+([\.-][a-z0-9]+))*$",$email$regs)){
          return 
    false;
       } else if( 
    gethostbyname($regs[2]) == $regs[2] ){
          
    // if host is invalid
          
    return false;
       } else {
          return 
    true;
       }
    }

    function 
    valid_userName($name){
       
    // check valid input name
       
    if(!eregi("^[a-z0-9]{8,15}$",$name)){
          return 
    false;
       } else {
          return 
    true;
       }
    }

    function 
    valid_password($pwd){
       
    // check valid password
       
    if(!eregi("^[a-z0-9]{6,8}$",$pwd))
       {
          return 
    false;
       } else {
          return 
    true;
       }
    }
    ?>
     

    and the meats.

    user.php

    Code: [Select]
    <?php
    require_once('config.php');
    require_once(
    'functions.php');
    // ---
    // register new user
    // ---
    function register($username,$pass,$email,$question,$answer)
    {
       GLOBAL 
    $db$table;
       
    $username trim($username);
       
    $pass trim($pass);
       
    $email trim($email);
       
    $question addslashes(trim($question));
       
    $answer addslashes(trim($answer));
       
    $validEmail valid_email($email);
       
    $validName valid_userName($username);
       
    $validPass valid_password($pass);
       if(!
    $validName) return "error=invalid name";
       if(!
    $validPass) return "error=invalid password";
       if(!
    $validEmail) return "error=invalid email";
       
    $pass md5(trim($pass));
       
    // all checks ok
       
    $query = @mysql_query("INSERT INTO $table (userName,userPassword,userMail,userQuestion,userAnswer) VALUES "
       
    ."('$username','$pass','$email','$question','$answer')");
       if(!
    $query)
       {
          return 
    "error=" mysql_error();
       } else {
          return 
    "user=ok";
       }
    }

    // ---
    // login, check user
    // ---
    function login($username,$pass)
    {
       GLOBAL 
    $db,$table;
       
    $username trim($username);
       
    $pass md5(trim($pass));
       
    $query mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userPassword = '$pass'");
       return 
    mysql_num_rows($query);
    }

    // ---
    // forget password
    // ---
    function forget($email)
    {
       GLOBAL 
    $db,$table;
       
    $email trim($email);
       
    $query mysql_query("SELECT userName, userQuestion from $table WHERE userMail = '$email'");
       if(
    mysql_num_rows($query)<1)
       {
          return 
    "error=email not present into database";
       }
       
    $row mysql_fetch_array($query);
       return 
    "userName=$row[userName]&userQuestion=" stripslashes($row['userQuestion']);
    }

    // ---
    // generate new password
    // ---
    function new_password($username,$email,$answer)
    {
       GLOBAL 
    $db,$table;
       
    $username trim($username);
       
    $email trim($email);
       
    $answer addslashes(trim($answer));
       
    $query mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userMail = '$email' AND userAnswer = '$answer'");
       if(
    mysql_num_rows($query) < 1)
       {
          return 
    "error=wrong answer";
       }
       
    $rand_string '';
       
    // ---
       // generating a random 8 chars lenght password
       // ---
       
    for($a=0;$a<7;$a++)
       {
          do
          {
             
    $newrand chr(rand(0,256));
          } while(!
    eregi("^[a-z0-9]$",$newrand));
          
    $rand_string .= $newrand;
       }
       
    $pwd_to_insert md5($rand_string);
       
    $new_query mysql_query("UPDATE $table SET userPassword = '$pwd_to_insert' WHERE userName = '$username' AND userMail = '$email'");
       if(!
    $new_query)
       {
          return 
    "error=unable to update value";
       }
       return 
    "userName=$username&new_pass=$rand_string";
    }

    // ---
    // decisional switch
    // ---
    if(isset($HTTP_POST_VARS["action"]))
    {
       switch(
    $HTTP_POST_VARS["action"])
       {
          case 
    "register":
             
    $result register($HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass'],$HTTP_POST_VARS['email'],$HTTP_POST_VARS['question'],$HTTP_POST_VARS['answer']);
             print 
    $result;
             break;
          case 
    "login":
             
    $result login($HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass']);
             print 
    "user=" $result;
             break;
          case 
    "forget":
             
    $result forget($HTTP_POST_VARS['email']);
             print 
    $result;
             break;
          case 
    "new_password":
             
    $result new_password($HTTP_POST_VARS['username'],$HTTP_POST_VARS['email'],$HTTP_POST_VARS['answer']);
             print 
    $result;
             break;
       }
    }
    ?>

    you can view example here

    http://streaminternetaccess.com/user_auth.html

    I can send you the flv file to look at the AS in frames.

    please help.

    here is the AS

    this is on the Login Frame
    Code: [Select]
    _global.php_file = "user.php";

    Stage.scaleMode = 'noscale';
    userName.background = true;
    userName.backgroundColor = 0xFFFFFF
    userName.border = true
    userName.borderColor = 0x666666
    userPassword.background = true;
    userPassword.backgroundColor = 0xFFFFFF
    userPassword.border = true
    userPassword.borderColor = 0x666666


    userName.restrict = "a-zA-Z0-9"
    userPassword.restrict = "a-zA-z0-9";

    stop();


    this is on the new_user Frame

    Code: [Select]
    stop();
    userName.background = true;
    userName.backgroundColor = 0xFFFFFF
    userName.border = true
    userName.borderColor = 0x666666

    userPassword2.background = true;
    userPassword2.backgroundColor = 0xFFFFFF
    userPassword2.border = true
    userPassword2.borderColor = 0x666666

    userPassword.background = true;
    userPassword.backgroundColor = 0xFFFFFF
    userPassword.border = true
    userPassword.borderColor = 0x666666

    userMail.background = true;
    userMail.backgroundColor = 0xFFFFFF
    userMail.border = true
    userMail.borderColor = 0x666666

    secretQuestion.background = true;
    secretQuestion.backgroundColor = 0xFFFFFF
    secretQuestion.border = true
    secretQuestion.borderColor = 0x666666

    secretAnswer.background = true;
    secretAnswer.backgroundColor = 0xFFFFFF
    secretAnswer.border = true
    secretAnswer.borderColor = 0x666666

    userName.restrict = "a-zA-Z0-9"
    userPassword.restrict = "a-zA-z0-9";
    userPassword2.restrict = "a-zA-z0-9";

    other frame forms alike.


    « Last Edit: 12/09/08, 19:32 by mikedhane »

    mikedhane

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Email
    Re: flash 8 AS 2 Help Help
    « Reply #1 on: 12/09/08, 19:32 »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: user login with mysql
    « Reply #2 on: 12/10/08, 02:41 »
    Hi and welcome at the boards.
    Even though this tutorial is not from us, I am trying to get you into the direction.
    Did you setup the database and tables?
    Did you modify the settings according to your server?
    Can you read and write to the database using phpMyAdmin (with the settings in you config.php file)?
    What happens, if you call the php file directly with the browser?
    Did you download Charles and checked messages there?
    Did you read, and understand, our loading and saving tutorials?

    Lots of questions, which will lead you to the solution.
    happy flashing
    8)
    Ronald

    mikedhane

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Email
    Re: user login with mysql
    « Reply #3 on: 12/10/08, 20:38 »
    I set up database and tabes
    yes i change the settings to connect to the sever

    {{{{{I can not read not write from the data base.}}}}}}

    when i load the file from the sever i see my favacon and blank screen.
    ex http://web.com/config.inc.php

    i viewed the source returned from the php in the bower and it returned this
    Code: [Select]
    <!-- www.000webhost.com Analytics Code -->
    <script type="text/javascript">
    var websiteID='vonzoo.com';
    </script>
    <script type="text/javascript" src="http://analytics.hosting24.com/s.php"></script>
    <noscript>
    <a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/s.php?websiteID=vonzoo.com" alt="web hosting" /></a>
    </noscript>
    <!-- End Of Code -->

    so i guess im connecting.

    i will work on getting Charles.  and post the returned on runs.

    & start on you loading and saving Tuts.

    I really am thankful for all the help.


    « Last Edit: 12/10/08, 20:43 by mikedhane »

    mikedhane

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Email
    Re: user login with mysql
    « Reply #4 on: 12/11/08, 01:24 »
    ok i now can get info to the sql


    now when i send info to sql it will  return upon successful input.

    yes step 1 done.

    now that the info is posted is will return to welcome page.

    the prob now is if the user has not registered they can still log any info in the fields
    that will not pass to the server and go to the welcome page anyway.

    here is the log in AS on the button

    Code: [Select]
    on (release)
    {
    if(userName.length > 8 && userPassword.length > 6)
    {
    myVars = new LoadVars();
    myVars.username = userName.text
    myVars.pass = userPassword.text
    myVars.action = 'login';
    myVars.sendAndLoad(php_file, myVars, 'POST');
    myVars.onLoad = function()
    {
    if(!this.error && this.user > 0)
    {
    _root.gotoAndStop('registered');
    } else {
    _root.gotoAndStop('no_registered');
    }
    userName.selectable = true;
    userPassword.selectable = true;
    loginButton.enabled = true;
    }
    userName.selectable = false;
    userPassword.selectable = false;
    loginButton.enabled = false;
    }
    }
    « Last Edit: 12/11/08, 03:51 by mikedhane »

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: user login with mysql
    « Reply #5 on: 12/11/08, 03:05 »
    to use charles:

    first start charles - then start your application
    charles will list all actions transfered to and from the internet.
    There you can see, if you mistyped a cariablename, or if the path is as expected, your script is throwing errors etc.
    happy flashing
    8)
    Ronald

    mikedhane

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Email
    Re: user login with mysql
    « Reply #6 on: 12/13/08, 01:29 »
    I found out it was a simple stop action that kept me from going to the no_registered page if there was no user. and go to the welcome page for known user and unknown user.

    I fixed that and everything runs fine on my localhost test.

    When i transfer everything over (and reset my sql connection for my php files)

    i am returned to the error no_reg. frames when i am connected to data base.

    i ran a test with the example file on the local and my servers
    with my php files and table.

    everything ran fine. all post worked.



    my Question now Is.
    what could cause this to happen.


    Charles said i'm returning user=1 when i login form my site with correct info
    so i know button var funciton is sending and receive-n from php and sql and posting the correct var user=1

    the tutorial example file loaded in my flash 8 as flash MX.

    could copying the old version affect the way it plays in the new version
    i thought mx and 8 were both AS 2.0

    I dont understand how it works fine in my localhost but not in server side with everthing set right.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: user login with mysql
    « Reply #7 on: 12/15/08, 07:13 »
    did you upload everything (the swf file as well) to the host?

    If path relations are the same, it should be working.

    Be aware: if you call your website wit www.website.com, and inside if the swf refer to website.com, you need a cross domain xml file, because it is seen as a different domain.
    happy flashing
    8)
    Ronald

    mikedhane

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Email
    Re: user login with mysql
    « Reply #8 on: 12/16/08, 06:52 »
    ok

    how do i do this

    Are you telling me I need to write a XML file for the swf file to direct to instead of point it directly to the html file.  i dont understand.

    I really need to get this going


    I found out that the contact form works.
    I receive to emails today from pissed off members wanting to log in.



     

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: user login with mysql
    « Reply #9 on: 12/16/08, 06:58 »
    did you try using charles?
    It tells you everything about the communication between your client and the server.
    It even tells you error messages, you otherwise would not receive.
    Could you give a life link, and tell me, how the php file, you are calling, is named.
    happy flashing
    8)
    Ronald

    mikedhane

    • Server what's that
    • *
    • Posts: 11
      • View Profile
      • Email
    Re: user login with mysql
    « Reply #10 on: 12/19/08, 17:21 »
    user.php