title: PHP MySQL while loop
body: <p>Why doesn't this code work? </p>
  
  <p>It creates a random number, if it exists in database then it generates a new one until it can insert into the unique key, if not then it inserts straight away into database.</p>
  
  <pre><code>$id;
      do {
      $id = mt_rand(1, 10);
      "SELECT count(*) FROM accounts WHERE id = '$id'";
      } while (count != 0);
  
      $sql = "INSERT INTO accounts (id, username, email, password, sex)
      VALUES ('$id', '$username', '$email', '$password', '$sex')";
  </code></pre>
  
  <p>The reason the mt_rand is low for testing purposes.</p>