User Log In Not getting accepted in PHP.

Discussion in 'PHP' started by rohitink, Sep 26, 2012.

  1. #1
    Hello, i have mentioned my code here already.
    I have a self made database with around 2 users only.

    So, when i enter correct information. I still get the message "Log In Not Accepted"!. The Error is in the line where $query is set. Because, on entering correct information. The num_rows() function returns ZERO.

    Also, since i am a beginner and working on a localhost, so i haven't added PD and all.

    if (isset($_POST['userpassword']))
            {
                include('db.php'); //I am using passwordu instead of password.
                $query = "SELECT * FROM users WHERE username = '".$_REQUEST['username']."' AND passwordu = '".md5($_REQUEST['userpassword'])."'";
                $result = mysql_query($query);
                $num_rows = mysql_num_rows($result);
                if ($num_rows == 1)
                {
                    echo "Congratulations. You are now Logged in. You will be logged out when the Browser is closed.";
                    $_SESSION['logval'] = TRUE;
                }
                else
                { 
                                echo "You Have Entered Wrong Information. <b>Please Try AGAIN."; }
    ?>
    PHP:
    Any help on why this code is not working, shall be greatly appreciated.
     
    rohitink, Sep 26, 2012 IP
  2. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #2
    Mhh.. Well, you could start by checking if you really get the data which you need

    meaning
    is the entered username - $_REQUEST['username'] correct?
    is the entered password - $_REQUEST['userpasswird'] and the generated MD5 hash correct?
    Is the MD5 hashed password in your database, or is it in plain text?
    Is the $query right?


    I somehow have the feeling that the MD5 is causing the problem


    Also: I see that one curly brace is missing at the end of the provided code. It's probably a copy-paste error, right?
     
    GMF, Sep 26, 2012 IP
  3. master-mind

    master-mind Well-Known Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #3
    You can also do echo before your actual statement ($query). That will print the executed statement on the page. Copy that statement and paste in phpmyadmin on your database. and run their. See if it throws any error their. It will most probably show you the error in there.
     
    master-mind, Sep 26, 2012 IP
  4. Web Solutions

    Web Solutions Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    0
    #4
    1. What is the purpose of using $_REQUEST instead of $_POST if you know you are working with HTTP POST method ?
    2. Are you sure you have a field called passwordu (not password) ?

    If nothing of this helps, check (simple echo should work) all of your variables before passing them any further.
     
    Web Solutions, Sep 26, 2012 IP
  5. gigpayrr

    gigpayrr Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    please take care for sql injections, your current code is not...
     
    gigpayrr, Sep 26, 2012 IP