title: Inserting into two different database tables
body: <p>I have a form that will insert users input from a form into database, I want to store the email in a separate table to the users.</p>
  <p>So I want the email in an accounts table and then the username and password in a users table. For anyone wondering why, the application I want to build will allow users to create a new user after dying but can have stuff stored in the accounts that will be carried over.</p>
  <p>I tried working with multiple of the same code but just gets too much and get lost in it all. There must be an easier way to do than multiple copied of stretched code.</p>
  <pre><code>$sql = &quot;SELECT user_name FROM users WHERE user_name=?&quot;;
      $stmt = mysqli_stmt_init($conn);
      if(!mysqli_stmt_prepare($stmt, $sql)) {
          header(&quot;Location: ../register.php?error=Sql_Error&quot;);
          exit();
          
      } else {
          
      
      mysqli_stmt_bind_param($stmt, &quot;s&quot;, $character);
      mysqli_stmt_execute($stmt);
      mysqli_stmt_store_result($stmt);
      $resultCheck = mysqli_stmt_num_rows($stmt);
          
       if ($resultCheck &gt; 0) {
           header(&quot;Location: ../register.php?error=CharacterTaken&amp;email=&quot;.$emailAddress); 
           exit();
       } else {
           
          $sql = &quot;INSERT INTO users (user_name, user_email, user_password) VALUES (?, ?, ?)&quot;;
          $stmt = mysqli_stmt_init($conn);
          if (!mysqli_stmt_prepare($stmt, $sql)) {
              header(&quot;Location: ../register.php?error=Sql_Error&quot;);
              exit;
              
              
          } else {
              
          $hashedPwd = password_hash($password, PASSWORD_DEFAULT);
              
          mysqli_stmt_bind_param($stmt, &quot;sss&quot;, $character, $emailAddress, $hashedPwd);
          mysqli_stmt_execute($stmt);
          header(&quot;Location: ../register.php?success=Account Created.&quot;);
  </code></pre>