The Little Guy Posted April 22, 2008 Share Posted April 22, 2008 What would be the best way in insert a random string into the database, but the string cannot already exist in the database (the string will be case sensitive)? I was just going to make a loop that will make a query more than one time if the string is already in the database, but is there a better way to do this? Link to comment https://forums.phpfreaks.com/topic/102243-insert-unique-random-string-into-database/ Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 What would be the best way in insert a random string into the database, but the string cannot already exist in the database? I was just going to make a loop that will make a query more than one time if the string is already in the database, but is there a better way to do this? Set the field as unique in the database, and use this to make a unique code. $code = md5(uniqid(rand(), true)); You can take a substr() of that to get the right # of chars if you want. Link to comment https://forums.phpfreaks.com/topic/102243-insert-unique-random-string-into-database/#findComment-523497 Share on other sites More sharing options...
The Little Guy Posted April 22, 2008 Author Share Posted April 22, 2008 thank you! Is there a way I can make some of the letters uppercase and some lowercase? Link to comment https://forums.phpfreaks.com/topic/102243-insert-unique-random-string-into-database/#findComment-523505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.