I want to check if a key exists in a MySQL DB. I can do this ok but I would need to create a new key if it does exist. So this is the function that makes the key: function keygen($a){ $b = str_shuffle('abcdefghijklmnopqrstuvwxyz1234567890'); return substr($b,0,$a); } PHP: So I thought about making a while loop to check if the key exists. But I don't know how to form it. Could someone explain please. Thanks.
There are hashing algorithms for this purpose already, like md5() and sha1(). $id = mysql_insert_id(); $hash = md5("my_salt_{$id}"); $sql = "update row set my_key = '{$hash}'"; $st = mysql_query($sql) or die(mysql_error()); Code (markup):
run the query select from table where key="yourkey" then use mysql_num_rows to see how many rows contain that key (should be 1 or 0 for you)