In your sample you reference a variable $_POST['email']
without assignment or testing the value. Additionally you may want to sanitize this variable.
Another issue I saw was that $to_delete = 'email';
, you are only looking for entries of 'email'.
Your $file_put_contents
is not being assigned.
} else { showForm(); }
wasn't paired up with an if statement.
' . PHP_EOL
. 'Email Address:
' . PHP_EOL
. '' . PHP_EOL
. '';
}
if($_POST['email']) {
$to_delete = $_POST['email'];
$file = array_flip(explode(",",file_get_contents("email.txt")));
unset($file[$to_delete]);
$file_put_contents = file_put_contents("email.txt",implode(",",array_flip($file));
if(!$file_put_contents) {
die('Error occured');
} else {
echo 'Your subscription has been cancelled. You will not receive any further emails from us.';
}
} else {
showForm();
}