mcmuney Posted February 18, 2012 Share Posted February 18, 2012 I am inserting the two records below simultaneously (one after the other), but what I want to do write the second ONLY if the first isn't a duplicate. Help? //FIRST INSERT mysql_query("INSERT INTO spam (id, scm_mem_id) VALUES('', '$social_mem_id' ) ON DUPLICATE KEY UPDATE scm_mem_id=$social_mem_id") or die(mysql_error()); //SECOND INSERT mysql_query("INSERT INTO sc_messages (smg_from, smg_to, smg_subject, smg_body, smg_sent_del, smg_postdate) VALUES ('$social_mem_id','1','$subject','$body','1','$time')") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/257274-help-with-on-duplicate-key/ Share on other sites More sharing options...
Pikachu2000 Posted February 18, 2012 Share Posted February 18, 2012 I haven't tested this theory, but you should be able to use mysql_insert_id to determine if the first query inserted a record or updated an existing one. Link to comment https://forums.phpfreaks.com/topic/257274-help-with-on-duplicate-key/#findComment-1318715 Share on other sites More sharing options...
mcmuney Posted February 18, 2012 Author Share Posted February 18, 2012 Perfect.. thanks! Link to comment https://forums.phpfreaks.com/topic/257274-help-with-on-duplicate-key/#findComment-1318723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.