I'm new to PHP and struggling getting a form started. I'm getting the following error -
Notice: Undefined index: email in C:\xampp\htdocs\Matt\login.php on line 7
Do I need to declare empty vars before code. My code;
<?php
if (array_key_exists("submit", $_POST)) {
print_r($_POST);
}
if (!$_POST['email']) {
$error .= "An Email is required<br>";
}
if ($error != "") {
$error = "<p>There were error(s) in your form:</p>".$error;
}
?>
<div class="error"><?php echo $error; ?></div>
<form method="post" id="logInForm">
<input type="email" class="form-control" name="email" id="email" placeholder="email">
<input type="password" class="form-control" name="password" id="password" placeholder="password">
<div class="checkbox pt-2">
<label>
<input type="checkbox" name="stayLoggedIn" value="1"> Stay Logged In
</label>
</div>
<input type="submit" name="submit" class="btn btn-primary btn-block mb-4" value="Log in!">
</form>