Many situations arise where you need to either insert or update some data in a table but which you will not be certain as to which function to perform. A common solution is to do a query on the table first to see if the data exists and then insert if it doesn't and update if it does. However, this creates an unnecessary overhead in that every time the code is run at least 2 queries are run.
A better way is to try to update the table and then use the mysql_info() function to detect how many rows where updated in the query and how many rows matched the parameters in the update query.
Take the following query.