Topic
  • 2 replies
  • Latest Post - ‏2014-09-20T11:37:21Z by jitupkp
NYnoob
NYnoob
2 Posts

Pinned topic Generate error messages within a login popup

‏2012-02-15T19:04:05Z |
Hi all,

I'm a noob hacker trying to get a rudimentary site up for practice. I would like to use the following script I found to have an overlay for my login for: http://www.skipser.com/p/94/p/popup-box-for-login-screen.html

I got the form to work with my database and it logs in a user. The only problem is that when the user does something wrong (enters incorrect information or leaves the fields blank), the popup closes and generates an error message on a new page with only the content of the popup.

I want the user to see the error message upon pressing submit but I can't seem to figure out how to do that.

Can anyone help me figure out how to make this work? You can download the code from the URL or from the attached files.

Thanks so much!
Updated on 2012-02-15T23:17:33Z at 2012-02-15T23:17:33Z by NYnoob
  • NYnoob
    NYnoob
    2 Posts

    Re: Generate error messages within a login popup

    ‏2012-02-15T23:17:33Z  
    The relevent PHP code is below:

    if (isset($_POST)&&isset($_POST)){
    $username = $_POST;
    $password = $_POST;

    $password_hash = md5($password);

    if(!empty($username) && !empty($password)) {

    $query="SELECT id FROM users WHERE username='$username' AND password='$password_hash'";

    if ($query_run = mysql_query($query)){
    $query_num_rows = mysql_num_rows($query_run);
    if ($query_num_rows==0){
    echo 'Invalid username and password combination.';
    header('Location: index2.php');
    }else if ($query_num_rows==1){
    $user_id = mysql_result($query_run, 0, 'id');
    $_SESSION=$user_id;
    header('Location: myProfile.html');
    }
    }

    } else {
    echo 'You must supply a username and password.';
    }
    }
  • jitupkp
    jitupkp
    104 Posts

    Re: Generate error messages within a login popup

    ‏2014-09-20T11:37:21Z  
    • NYnoob
    • ‏2012-02-15T23:17:33Z
    The relevent PHP code is below:

    if (isset($_POST)&&isset($_POST)){
    $username = $_POST;
    $password = $_POST;

    $password_hash = md5($password);

    if(!empty($username) && !empty($password)) {

    $query="SELECT id FROM users WHERE username='$username' AND password='$password_hash'";

    if ($query_run = mysql_query($query)){
    $query_num_rows = mysql_num_rows($query_run);
    if ($query_num_rows==0){
    echo 'Invalid username and password combination.';
    header('Location: index2.php');
    }else if ($query_num_rows==1){
    $user_id = mysql_result($query_run, 0, 'id');
    $_SESSION=$user_id;
    header('Location: myProfile.html');
    }
    }

    } else {
    echo 'You must supply a username and password.';
    }
    }

    get more help

    http://techgurulab.com/course/ajax-quiz-online/