Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validating system user

    Hi, i have a problem regarding validating user from login form, matching to the registered user in mysql database.

    here's the code:

    login form codes:

    <html>
    <form method="POST" action="login.php">
    <font color="white">Username <input type="text" name="username"><br>
    <font color="white">Password <input type="password" name="password"><br>
    <input type="submit" value="Login">
    </form>
    </html>

    this is the login.php page:

    <?php

    $my_connection = mysql_connect('localhost','root','');
    if(!$my_connection)
    {
    die('Could not connect: '.mysql_error());
    }
    echo'Connected Succesfully to mySQL server' . '<br><br>';
    $my_database = mysql_select_db('mydb');
    if(!$my_database)
    {
    die("Could not find database: ".mysql_error());
    }



    $select_user = mysql_query('select * from users where username =
    "' . $_POST['username'] . '" and password = "' .$_POST['password'] . '"')or die(mysql_error());



    if (mysql_num_rows($select_user) != 0) {

    session_start();
    session_register('authorized');
    $_SESSION['authorized'] = true;

    header("Location: protected_content.php");
    exit;

    } else {

    header("Location: login_form.php");
    exit;

    }


    it seems nothing happened, the condition is always '0' why is that?

    the value of conditional statement is always zero.

    im using an encryption of md5 for the password, please help...thanks in advance
    Last edited by badidoy; 03-06-2009 at 03:45 AM.

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    You have some misplaced quotes here:
    PHP Code:
    password '".md5($_POST['password'] )."'")or die(mysql_error()); 
    Also some of your parenthesis were misplaced.

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, thank you very much...Buddy!!!


  •  

    Posting Permissions

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