Thread: What's wrong?
View Single Post
Old 09-20-2007, 12:20 PM   #7 (permalink)
Karl
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

OK, the better way to achieve this is to frist execute the INSERT query which will fail on duplicates (assuming of course, you have approprirate PK/unique fields). You then simply determine if the last INSERT actually inserted any data (using mysql_affected_rows), finally, if no data was inserted, you can simply UPDATE the user record. The code should look like this:

PHP Code:
Execute INSERT query

if (mysql_affected_rows() == -1)
{
       
Execute UPDATE query

Karl is offline  
Reply With Quote