homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Deleting nothing from a database!
a question..

 10:23 am on Sep 28, 2003 (gmt 0)

I have this script I`m working on that displays an unsubscribe link in the e-mails that get sent out. So, its something like:


Now when its clicked on it deletes the e-mail from the database.

if ($action == "unsubscribe")


$query = "DELETE FROM list WHERE listemail = '$email'";
$result = mysql_query($query);

if (!$result)


echo "Account has already been removed!";




Now the problem I have is that if the link is clicked on a second time, when there is no e-mail address in the database, it still displays the emailRemoved() function instead of the echo statement.

I`ve tried (!$result) and (empty($result)) but its still the same.

So how do I get the echo statement to display if theres nothing to delete?




 10:41 am on Sep 28, 2003 (gmt 0)


The problem is that a DELETE query always returns TRUE, as long as the query was formally OK. From the PHP manual:
A non-FALSE return value
means that the query was legal and could be executed by
the server. It does not indicate anything about the number of
rows affected or returned. It is perfectly possible for a query
to succeed but affect no rows or return no rows.

What you need is
[url=http://www.php.net/manual/en/function.mysql-affected-rows.php]mysql_affected_rows()[/url], After a DELETE query it returns the number of deleted rows, and obviously 0 if no row has been deleted.
This should do the trick.


 11:16 am on Sep 28, 2003 (gmt 0)

Thanks mapostel, it works like a charm!


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved