IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
2 replies Latest Post - ‏2014-09-20T11:37:21Z by jitupkp
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:

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
    2 Posts

    Re: Generate error messages within a login popup

    ‏2012-02-15T23:17:33Z  in response to NYnoob
    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');
    header('Location: myProfile.html');

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