Okay I have put together the most SIMPLE form and database possible in order to hopefully get some guidance in debugging PHP.
LoginForm.php:
<?php
session_start();
$conn = new PDO('mysql:host=localhost;dbname=login', 'root', '');
if (isset($_POST['login']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$query = $conn->prepare("SELECT COUNT('id') FROM 'users' WHERE 'username' = '$username' AND 'password' = '$password'");
$query->execute();
$count = $query->fetchColumn();
if ($count == "1")
{
$_SESSION['username'] = $username;
header('location: Form.php');
}
}
?>
//THIS IS FORM - This code is underneath the code above.
<html
<head>Welcome to the Gym Login System</head>
<body>
<div id="Form">
<form method = "post" name="login">
<p>
<label>Email:</label>
<input type="text" name ="username" />
</p>
<p>
<label>Password:</label>
<input type="text" name="password" />
</p>
<p>
<input type ="submit" name="login" value ="Login" />
</p>
</form>
</div>
</body>
</html>
I have created a user in the database "login" in the table "users" with the following: username:test, password:test123
I tried to use this user to log into the "website to be" (only practicing), however the page loginForm.php page just refreshes, but it should have taken me to Form.php? Let me know if you need anymore information.