coding for 'no match found'
| From: | midget2000x | Date: | Tue, 15 May 2001 21:00:27 +0000 |
| Subject: | coding for 'no match found' | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-52944@lists.php.net to get a copy of this message | ||
This is a simple yet fundamental programming question I am hoping somebody will
have the patience to explain...
I have a mysql database with the "email" field as the key. Before inserting an
new record to it I want to check if there is already a record with that e-mail.
This I can do fine. But this script needs to also handle delete requests,
which I can also do fine, but I need to code for the instance that there is a
delete request for an e-mail record that does not exist. How can I figure out
if after my 'while' loop is finished checking the database it has not found a
match (so i can inform the requester as such)?
Here's the code I have so far...
$email_check_query = "SELECT email FROM $tablename WHERE email = '$email'";
$email_check_result = mysql_query($email_check_query);
while($email_query_data = mysql_fetch_array($email_check_result)) {
$db_email = $email_query_data["email"];
//if match, it's an update or delete
if ($email==$db_email) {
if ($op=="delete") {
$action="del";
echo "delete request<br>";
}
else {
$action = "upd";
echo "update request<br>";
}
}
} //end while loop
-----------
providing the finest in midget technology