Hi, im a newbe to php. I want to create a six digit random number as an ID but would like to also check if its not been already used within the database. Here is the code I have so far.. [code] $chars_for_actnum = array ("1","2","3","4","5","6","7","8","9","0"); for ($i = 1; $i <= 6; $i++) { $actnum = $actnum . $chars_for_actnum[mt_rand (0, count ($chars_for_actnum)-1)]; //make a loop so we can check the database if ID has already been taken. if it has we will genarate another ID. $query = "Select * from ".$DBprefix."client_info where id='$actnum'"; $result = mysql_query($query); if ($row = mysql_fetch_array($result)){ if ($row["id"] == $actnum) } }[/code] Any help will be much appreciated. Thx [b]EDITED BY WILDTEEN88: PLEASE USE THE CODE TAGS WHEN POSTING CODE, THANK YOU[/b]