So i have created a user_login.php page (consisting of html, a login form), the form is :
<form method="post" action="scripts/login.php">
<p>Username: <input type="text" name="Username" /></p>
<p>Password: <input type="password" name="Password" /></p>
<p><input type="submit" value="Sign In" /></p>
</form>
As well as this, I have a login.php script (see below)
<?php
include "scripts/connection.php";
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($link,$_POST['Username']);
$mypassword = mysqli_real_escape_string($link,$_POST['Password']);
$sql = "SELECT * FROM Customer WHERE Customer_Username = '$myusername' and Customer_Password = '$mypassword'";
$result = mysqli_query($link,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
$_SESSION['Username'] = $myusername;
header("location: Welcome.php");
}else {
$error = "Your Username or Password is invalid";
}
}
?>
Now i know my connection.php works, as I use it elsewhere on my site.
My problem is, when i browse the user_login.php page in my browser,when I click on the "sign in" button, it takes me to www.website.com/login.php file, but the entire page is blank (white). This happens no matter if i input something into the username and password fields or leave them blank.
Obviously what i require is, if the fields are blank or dont match records within the DB, an error message is displayed. If the logins do match then they are redirected to the Welcome.php file.
Not 100% if the login.php script is missing anything so any help would be much appreciated.
UPDATE
After adding :
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
include "scripts/connection.php";
to the top of my code, im getting a long error message now, instead of a pure white screen:
Warning: include(scripts/connection.php): failed to open stream: No such file or directory in scripts/login.php on line 5
Warning: include(): Failed opening 'scripts/connection.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in scripts/login.php on line 5
Notice: Undefined variable: link in scripts/login.php on line 10
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in /scripts/login.php on line 10
Notice: Undefined variable: link in /scripts/login.php on line 11
Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in /scripts/login.php on line 11
Notice: Undefined variable: link in /scripts/login.php on line 14
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /scripts/login.php on line 14
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /scripts/login.php on line 15
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /scripts/login.php on line 18