This question already has an answer here:
My code is working fine but every time the page has loaded an error shows at the top of the screen saying:
Undefined index: userKeySubmitted in C:\xampp\htdocs\Lunabooster 2\cp\index.php on line 4
Note that the login system
I've tried rearranging the code and what not but still same error.
Here's my full PHP code:
<?php
session_start();
$userKey = $_POST['userKeySubmitted'];
$keylist = file ('priv/keys.txt');
$success = false;
foreach ($keylist as $key) {
$user_details = explode('|', $key);
if ($user_details[0] == $userKey) {
$success = true;
if ($success) {
$_SESSION['userKey'] = $userKey;
header('Location: user.php');
break;
} else {
break;
}
}
}
?>
</div>
Because when the page load, there is no userKeySubmitted
index You need to check if the index exist first :
$userKey = isset($_POST['userKeySubmitted']) ? $_POST['userKeySubmitted'] : null;