On Wed, March 21, 2007 5:40 pm, ccspencer@xxxxxxxxxxxx wrote: > Thanks. Yes, I check for errors. But there are other types of errors > so I'd need to verify that it is a duplicate key error and, in my > ignorance, I have not yet figured out how to do that programatically. > I worry about getting into an infinite loop. Untested code: //create table test_id (id char(32) unique not null primary key)); $success = 0; while (!$success){ $id = md5(uniqid()); $query = "insert into test_id (id) values('$id')"; $result = mysql_query($query); if (!$result){ //I don't promise 1023 is right. //force a duplicate as a test to confirm if (mysql_errno() == 1023){ //duplicate key //we'll loop back and try with another } else{ echo "<p>Something went wrong with our database. Sorry."; error_log(mysql_error()); break; } } else{ $success = 1; } } -- 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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php