Replace or Update a Table Row – based on the presence of a matching row item

Unfortunately I know next to nothing about php coding that contains some sql code. The examples I have seen online do not seem to match the same syntax that I inherited with this code, which is making this task confusing for me.

I have a database table called "effort" that contains two columns:

Column 1 = ad  Column 2 = theEffort 


 This line of code below works, and it will populate the table with the proper values for both the "ad" and "theEffort" 

$  sql = "INSERT INTO effort SET ad='$  ad', theEffort='$  theEffort'"; 


 But I do not want the table to grow over time and contain redundant rows pertaining to the same ad. Each "ad" in this table should be unique. But each "ad" could have 5 different effort values, e.g., "theEffort" can be "easy", "medium", "difficult", "impossible".

The "ad" is 13 digit number, i.e. SFAD_000001234

Does anybody know how to modify my code above using similar syntax so that it would first check to see if the "ad" exists in the database table called "effort". And if so, instead of entering a new row it would update "theEffort" to the new value. And if the "ad" did not exist in any table row within the "effort" database then it would execute the INSERT INTO function, i.e., insert both the "ad" and "theEffort" as a new table row.

Thank you in advance, -Jeff