Q:

Fetching results from a prepared select query

I'm trying to create a basic log-in system. Username and password are entered into a form and the results are sent to this page. If I enter the correct details, it works fine, but if I try to log-in with nonsense it never displays the error message. The line seems to be skipped every single time. 

if(isset($_POST['submit'])) {

$sql = "SELECT username,password FROM tbl_users WHERE username = ? AND password = ?";
$stmt = $mysqli->prepare($sql);

if(!$stmt) {
    die("Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error);
}

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

$bind_result = $stmt->bind_param("ss", $username, $password);
if(!$bind_result) {
    echo "Binding failed: (" . $stmt->errno . ") " . $stmt->error;
}

$execute_result = $stmt->execute();
if(!$execute_result) {
    echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}

$stmt->bind_result($returned_username, $returned_password);

while($stmt->fetch()) {

    if($_POST['username'] == $returned_username && $_POST['password'] == $returned_password) {
        echo "You are now logged in!";
    } else {
        echo "Incorrect username or password";
    }
}

echo $stmt->fetch();

include 'disconnect.php';

}

A:

this should work...
$username = $_POST['username'];
$password = $_POST['password'];

$sql = "SELECT password FROM tbl_users where username = ?";
$stmt= $conn->prepare($sql);

$result->bind_param('s',$username); 
$result->execute();
$result->bind_result($pass);

$stmt->fetch() 
    // echo "<pre>"; print_r($pass);

    if($pass == $password) {
        echo "You are now logged in! <br><br>"; 
    } 
    else{
        echo 'Incorrect username or password<br>';
    }

comment if not working...

