I am somewhat new to PHP, but I am doing a course based on it at the moment.
I have a form where the user will input their email address in order to delete it from an email list.
I am trying to make an if else statement that when their email is not in the database it will error with “do not exist in the list”.
As you can probably see the script does not work.
How can I see if the query succeeded and then return an appropriate message to the user?
$email = $_POST['email'];
$dbc = mysqli_connect(censored)
or die('error connecting to the database');
$query = "DELETE FROM email_list WHERE email='$email'";
$result = mysqli_query($dbc, $query)
or die('Error Querying the database');
if ($result == 0) {
echo $email . ' do not exist in the list';
}
else {
echo $email . ' is deleted form the list';
}
mysqli_close($dbc);
mysqli_affected_rows()