**So, this is my code for a log in page. The problem I have is that when I click the button to log in I get this outcome which does not help me in any way to see my mistake -
I do not understand why I get this as an outcome.
I have a working sign up page which is capable of sending the sign up data to the database where it is stored. When I try to log in with this data though, it does not recognise the data. I checked a few times the code, I am still new to php and can not find the problem.
I hope it is not a stupid question. Thank you in advance!
PHP Log in
<?php>
session_start();
$error='';//here we store potential errors
if(isset($_POST['submit'])) {
if(empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or password invalid";
}
else
{
//define the variables
$username = $_POST['username'];
$password = $_POST['password'];
//connection
$conn= mysqli_connect("host","***","***","***");
$query = "SELECT * FROM user WHERE username='$username' AND password='$password'";
$stmt = $conn->prepare($query);
$stmt->bind_param("ss",$username,$password);
$stmt->execute();
$stmt->bind_result($username,$password);
$stmt->store_result();
if($stmt->fetch())
{
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header("location: index.php");
}
else{
$error="Username or Password invalid";
}
mysqli_close($conn);
}
}
?>
?>
Log In form
<?php
include_once 'header.php';
?>
<div class="header">
<h2>Login</h2>
</div>
<form method="post" action="Log.php">
<?php include('errors.php'); ?>
<input placeholder="Username" type="text" name="username" >
<input placeholder="Password" type="password" name="password" >
<input type="submit" name="submit" >
<p>
Not yet a member? <a href="register.php">Sign up</a>
</p>
</form>
<?php
include_once 'footer.php';
?>