Is there a way to know if a row is updated?

I need to make an updated query like this:

"UPDATE users SET email_code='1' WHERE id=".$id." AND email_code='".$email_code."'";

and if the row is updated, then set $_SESSION['verified']=1

So I have to know if that row is updated.

Is there a way to know that ? Or I have to make first a SELECT query to know if that row exists ?


You can use mysqli_affected_rows to see if any rows were changed after you execute the query.

if(mysqli_affected_rows($link) > 0){
    // do session stuff

You could set a trigger in MySQL on UPDATE for the users table and have MySQL run a script to set some variable which would access that session. But that'd be an unnecessarily huge pain in the rear.

I'd create an AJAX heartbeat on the page necessary to check and see if that row exists and then update the session that you need. Cleaner that way.

Among the mysql_ and mysqli_ family of functions there is mysqli_affected_rows and mysql_affected_rows. I'm not very familiar with PDO, but that must have something similar, for sure.

You could also check if the query returned true or false and set $_SESSION['verified'] accordingly.

Need Your Help

How do I play a .wav upon having someone click a link

audio hyperlink click wav effect

I have a .wav that I want to play when a person clicks on a link. How do I go about doing that? I'm not exactly an expert at html or css or javascript so be gentle with me

How do I use grunt-sweet?

gruntjs sweet.js

I would like to set up grunt sweet so that I can have it start watching my sweetjs-using files and compile them as they change.