title: How to see if random number already exist in database?
body: <p>I'd like my page to create a random number (numbers only). This needs to be a unique number. So, after the number is created, the code should check the database if this number doesn't already exist. If so, it should generate a new number and repeat the check. If the number's unique, the code can continue. What I have results in a page crash. What am I doing wrong?</p>
  
  <pre><code>$randomNR = mt_rand(10000,1000000000);
  
  function newRandNR() {
      $randomNR = mt_rand(10000,1000000000);
  }
  
  function checkRandNR() {
      $stmt = $mysqli-&gt;prepare("SELECT * FROM accounts WHERE uid = ?");
      $stmt-&gt;bind_param("i", $randomNR);
      $stmt-&gt;execute();
      $stmt-&gt;store_result(); 
      if ($stmt-&gt;num_rows != 0) {
          newRandNR();
      }
      $stmt-&gt;close();
  
  }
  
  checkRandNR();
  </code></pre>