pneudralics Posted September 26, 2009 Share Posted September 26, 2009 Let's say for some reason my md5 string is in the database. How can I repeat md5ing strings until one is not found? <?php $string = md5($_POST['string']); if (isset($_POST['submit'])) { $query = "SELECT * FROM table WHERE string = '$string' LIMIT 1"; if ($result = mysql_query($query)) { $row = mysql_num_rows ($result); if ($row = 0) { //insert to database } else { //Repeat md5 string until none is found in database } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/175614-how-can-i-loop-this/ Share on other sites More sharing options...
smerny Posted September 26, 2009 Share Posted September 26, 2009 i don't really understand what you are trying to do Quote Link to comment https://forums.phpfreaks.com/topic/175614-how-can-i-loop-this/#findComment-925393 Share on other sites More sharing options...
pneudralics Posted September 26, 2009 Author Share Posted September 26, 2009 If the posted string that just got hashed with md5 is already in the database I want to be able to repeat the hashing process until none is found in the database. Then I will allow it to insert into the database. Quote Link to comment https://forums.phpfreaks.com/topic/175614-how-can-i-loop-this/#findComment-925404 Share on other sites More sharing options...
smerny Posted September 26, 2009 Share Posted September 26, 2009 what is the point? you wouldn't be able to compare that string to it later do you want to be able to compare this string later? what is the reason you don't want the same hash to exist more than once? what are you planning to do with it? Quote Link to comment https://forums.phpfreaks.com/topic/175614-how-can-i-loop-this/#findComment-925408 Share on other sites More sharing options...
pneudralics Posted September 26, 2009 Author Share Posted September 26, 2009 Yes I do want to be able to compare it later. Later on I want to be able to add uploaded hashed image names to the database. I don't want the same ones to exist. Quote Link to comment https://forums.phpfreaks.com/topic/175614-how-can-i-loop-this/#findComment-925414 Share on other sites More sharing options...
PFMaBiSmAd Posted September 26, 2009 Share Posted September 26, 2009 In your previous thread on this, someone already mentioned how you could use a unique key - if you are using mysql, and the random string is a key, you can use INSERT IGNORE or INSERT...ON DUPLICATE UPDATE queries. Quote Link to comment https://forums.phpfreaks.com/topic/175614-how-can-i-loop-this/#findComment-925417 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.