Understanding Nested If.. Else statements

Posted by user1174762 on Stack Overflow See other posts from Stack Overflow or by user1174762
Published on 2012-04-10T23:22:08Z Indexed on 2012/04/10 23:28 UTC
Read the original article Hit count: 216

Filed under:
|

For some reason my PHP login script keeps returning "invalid email/password combination", yet i know I am entering the correct email and password. Does anyone see what I might be doing wrong?

<?php

$email= $_POST['email'];
$password= $_POST['password'];

if (!empty($email) && !empty($password)) 
{
    $connect= mysqli_connect("localhost", "root", "", "si")
    or die('error connecting with the database');

    $query= "SELECT user_id, email, password FROM users WHERE email='$email' AND password='$password'";
    $result= mysqli_query($connect, $query)
    or die('error with query');
    if (mysqli_num_rows($result) == 1) 
    {
        $row= mysqli_fetch_array($result);
        setcookie('user_id', $row['user_id']);
        echo "you are now logged in";
    }
    else 
    {
        echo "invalid username/password combination";
    }
}
else 
{
    echo" you must fill out both username and password";
}

?>

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql