Re: Add New Records Only!

From: Date: Mon, 26 Mar 2007 20:13:11 +0000
Subject: Re: Add New Records Only!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-251414@lists.php.net to get a copy of this message
On Mon, March 26, 2007 2:28 pm, Rahul Sitaram Johari wrote: >> Another option would be to just create a UNIQUE INDEX on the fields >> you think "should" be unique, and then your second insert is gonna >> fail, and you can just ignore that. > > Could you possibly elaborate on this? > Things I'm trying are still not working out the way or want to, or > efficiently. So still looking for a solution. create unique index no_duplicates on whatever(field1, field2, field3); $query = "insert into whatever (field1, field2, field3) values('$field1_sql', '$field2_sql', '$field3_sql')"; $insert = mysql_query($query, $connection); if (!$insert && mysql_errno($connection) == 1062){ //this is a duplicate insert that failed. do whatever you want here } elseif (!$insert){ //something else went wrong with the insert. //provide usual debugging error handling here } else{ //everything went fine here } -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

« previous php.general (#251414) next »