Hello there. I have the following login script and despite the form being placed just above the script, it claims it cannot find it and that the index is undefined. Is there an extra pair of eyes that can help me figure out what I’m missing. Thank you.
<form method='POST' action=''>
Email: <br> <input type='email' name='email' required > <br> <br>
Password: <br> <input type='password' name='password' required /> <br> <br>
<input type='submit' value='sign in' />
</form>
<?php
include_once "../classes/my_conn.php";
include_once "../classes/member_class.php";
$user_email = $_POST['email'];
$user_password = $_POST['password'];
// validation function
function auth_user($email, $password, $connect){
$query = $connect->prepare("SELECT * FROM users WHERE email=?");
$query->execute([$email]);
if (!$query->fetchColumn()) {
return false;
}
else {
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
if (!password_verify($password, $row['password'])) {
return false;
}
else {
$_SESSION['username'] = $row['username'];
}
}
}
}
if (!empty($user_email) && !empty($user_password)) {
// get connection
$conn = new My_conn($conn_vars);
$conn = $conn->gc();
$user_email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (isset($_SESSION['username'])) {
header('Location:http://blog.agwconitsha.org/');
}
else {
var_dump(auth_user($user_email, $user_password, $conn)); /* this is returning NULL since the defined vars are supposedly undefined */
if (!!auth_user($user_email, $user_password, $conn)) {
header('Location: mysite.com');
}
echo '<p style="color:#900;">*incorrect email or password</p>';
}
}
?>