title: Check if Random Exist in the database before inserting
body: <p>i made a small code that generates different type of code, but i'll make it simpler, </p>
  
  <p>i have a registration form submitted while submitting i collect some info about the user and i create for him a random, but i want this random to be unique for this user.</p>
  
  <p>so i have 3 cases :</p>
  
  <pre><code>$code_random = rand(1000,9999);
      if($code_random &lt; 0){
      $code_random = -$code_random;
      }
  
  $random = $fname.$code_random; //case 1
  $random = $lname.$code_random; //case 2
  $random = $fname.lname.$code_random; //case 3
  </code></pre>
  
  <p>But i want to create case 1 check if this random exist in the database, if it does use the second case if it does use the third case, before submitting the form and without displaying anything for the user.</p>
  
  <p>Thanks for your help in advance.</p>