title: INSERT into MYSQL and then before closing the connection select the insert id and then adding this id to 3 other tables
body: <p>I am pretty new to the world of SQL so sorry for my ignorance on this. </p>
  
  <p>I have a form on an admin page that adds a player to a team database. When the form is submitted what I need to have happen is: </p>
  
  <ul>
  <li><p>The player gets inserted into players table (player_id is Primary key and used in next step).</p></li>
  <li><p>A select statement runs to get the player_id.</p></li>
  <li>Then inserts that into 2 other tables: 
  
  <ul>
  <li>team_players and cards.  </li>
  </ul></li>
  </ul>
  
  <p>Below is the best representation of what I have tried:</p>
  
  <pre><code>if(isset($_POST['submit'])){ 
  
  $first_name = mysqli_real_escape_string($con2, $_POST['first_name']);
  $last_name = mysqli_real_escape_string($con2, $_POST['last_name']);
  $email = mysqli_real_escape_string($con2, $_POST['email']);
  $validation_code = md5($email + microtime());
  
  
  $sql0 ="INSERT INTO players 
  (first_name, last_name, email, validation_code)                        
  VALUES ('$first_name', '$last_name','$email', '$validation_code')";
  
  
  
  $sql01 = "SELECT player_id FROM players WHERE email='$email'";
  $result01 = $con2-&gt;query($sql01);
  
  if ($result01-&gt;num_rows &gt; 0) {
  $row01 = $result01-&gt;fetch_assoc();
  
  $playerID = $row01['player_id'];
  echo $playerID; //In for debugging. Sometimes it works sometimes it doesn't
  
  
  $sql02 = "INSERT INTO team_players, cards (player_id, team_id)
  VALUES('$playerID', '$id')";
  </code></pre>
  
  <p>Thanks for any help on this.</p>