Deleting nothing

Post here if you need help with SQL.
Post Reply
User avatar
FrederickGeek8
Posts: 148
Joined: Wed Nov 30, 2011 10:31 pm

Deleting nothing

Post by FrederickGeek8 »

If it ok if I'm running a query that is determined by a $_GET variables that deleted from a table, even if there is nothing there? Like if I run this query it runs fine (no errors) but I'm wondering if there is any downside to using it
DELETE FROM `reset_codes` WHERE `reset_code` = 'nonexistantvalue'
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Deleting nothing

Post by Temor »

Well, it's wasted computing power. But I don't think it's harmful if thats what you mean.
User avatar
FrederickGeek8
Posts: 148
Joined: Wed Nov 30, 2011 10:31 pm

Re: Deleting nothing

Post by FrederickGeek8 »

OK. I would think that it would be more wasteful if I did
$total = mysql_query("SELECT COUNT(`user_id`) FROM `reset_codes` WHERE `reset_code` = '{$reset_id}'");
if($mysql_result($total, 0) == '1'){
mysql_query("DELETE FROM `reset_codes` WHERE `reset_code` = '{$reset_id}'");
}else{
$errors[] = 'Invalid reset code.';
}
I think I'm going to stick with the way it is. The only thing I was worried about was security (not that things weren't sanitized, it just felt weird that a user directly hooked into a db)
Post Reply