I have written a login script using mysqli and the complete script works up till the part where I've actually entered correct details. If I leave the fields blank or input incorrect details it displays a message to the user .. which is great! But say I enter the correct username and password combination.. it doesn't direct to the page I've asked it to.. it just shows me a white screen... see code below:
<?php
// Create a connection
include("dbconfig.php");
if( isset( $_POST['submit'] ) ){
if( empty( $_POST['username'] ) or empty( $_POST['password'] ) ){
header("location:index.php?msg0=Please complete the required fields.");
} elseif ( !empty( $_POST['username'] ) && !empty( $_POST['password'] ) ){
$username = $_POST['username'];
$password = $_POST['password'];
$sql = mysqli_query($conn, "SELECT username, password FROM logininformation WHERE username = '$username' and password = '$password'") or die (mysqli_error($conn));
$login = ($sql) ? mysqli_fetch_assoc($sql) : false;
if( $login == 0 ){
header("location: index.php?msg1=Invalid username or password, please try again.");
} elseif( $login == 1 ){
header("location: userlogin.php?uid=$username");
}
}
}
?>
Please could someone advise me on what I'm doing wrong. Help will be much appreciated.
Thanks,
Sohail.