I have a problem with checking if a MySQL update statement succeeded. I want to update the users email. But they have to authorize themselfs with a token. I already used mysql_affected_rows bu when a user submits the same email as there was in the database before, the affected rows will be 0 instead of 1.
How can i check if there was a row in users with that token even when the new email is the same as before?
UPDATE users SET email = '".$email."' WHERE token = '".$token."'
This user contribution in the PHP Manual for
mysql_affected_rowsshows a hacky way to extract the number of rows matched from a call tomysql_info(). It really is hacky, though. (EDIT: There’s another version in the user notes formysql_infowhich is more general, but still hacky.)What I would do is use a separate query:
"select count(token) as matches from users where token = $token"