I'm new to PHP. I'm making a login form. Here's my html:
<form method="POST" id="login_form" action="log_in.php">
<div class="form-group">
<label for="Username">Username</label>
<input autocomplete="off" type="text" class="form-control" id="username" required>
</div>
<div class="form-group">
<label for="Password">Password</label>
<input autocomplete="off" type="password" class="form-control" id="password" required>
</div>
<button type="submit" id="submit_login" class="btn">Log in</button>
</form>
Here's my log_in.php
<?php
include("db.php");
if ($_SERVER['REQUEST_METHOD']=='POST') {
$username = $_POST["username"];
$password = $_POST["password"];
$stmt = $conn->prepare("SELECT * FROM users WHERE username=? AND pass=?");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$result = $stmt->get_result();
$check = mysqli_num_rows($result);
if ($check > 0) {
while ($row = $result->fetch_assoc()) {
if ($username == $row['username'] && (password_verify($password, $row['pass']) || $password == $row['pass'])) {
if ($row['stat'] == "Admin") {
$conn->close();
header("Location: admin.php");
break;
} else {
$conn->close();
header("Location: member.php");
break;
}
}
}
}
}
else {
echo "<script>";
echo "alert('No Matching Records!');";
echo "</script>";
}
?>
The problem is that I think the button does not submit the username and password to the server. i get an error Undefined index:username, and Undefined index:password. and it does not log in and load to the header destination. i cant find the problem. thank u in advance!