Hi (again), apologies, this is my third post today, learning well but need a little help…
I have written a script to delete an email address from the database when a user writes in a feild their address. It works perfectly and does remove their email address but if I type in an address that does not exist in the database, the message is still echoed that it has been removed, want it to say ‘Email Address not found’.
Sure this is something small and simple to do
<?php
if ($_POST['remove']!=""){
include_once('connection.php');
$remove = $_POST['remove'];
$sql_search = mysql_query("SELECT * FROM addresses WHERE email='$remove'");
if ($sql_search) {
$sql_remove = mysql_query("DELETE FROM addresses WHERE email='$remove'");
echo $msg_to_user = '<div class="msg_to_user_success">Email address removed successfully.</div>';
}
else {
echo $msg_to_user = '<div class="msg_to_user">Cannot find address in Database.</div>';
}
}
else { $msg_to_user = ""; }
?>
Because if your select doesn’t return any rows, the ‘if’ is still true. It’s only false if the query ends with an error. Check for mysql_num_rows($sql_search) > 0 instead.