Page 1 of 1

correct update query mysql (simple)

Posted: Mon Jun 27, 2005 7:00 am
by bytte
Is this query correct?

Code: Select all

UPDATE mailinglist SET active = 1, activated_dt = NOW() WHERE active = 0 AND pass = 'ec1f825b' AND ID = '3'
It appears to update the record even if the pass value is not correct.

Any idea?

Posted: Mon Jun 27, 2005 7:04 am
by Chris Corbyn
It sure looks OK to me :?

Could you maybe send the SQL export? Though what difference it'll make I'm not sure.

Posted: Mon Jun 27, 2005 7:29 am
by bytte
Oh, excuse me. It doesn't update the record (which is normal, if $act is not correct, but my code still returns TRUE.
This is the exact code:

Code: Select all

function activateAddress($ID,$act) {
$sql = &quote;UPDATE
					mailinglist
				SET
					active = 1,
					activated_dt = NOW()
				WHERE
					active = 0 AND
					pass = '&quote; . $act . &quote;' AND
					ID = '&quote; . $ID . &quote;'&quote;;
		$result = mysql_query($sql);
		if (!$result) {
			return FALSE;
		} else {
			return TRUE;
		}
}

Posted: Mon Jun 27, 2005 8:05 am
by Syranide
as the query was valid it returns TRUE;
what you want is mysql_affected_rows.

Posted: Mon Jun 27, 2005 8:12 am
by bytte
:oops:
Thanks.