title: How to fill multiple tables of a database in phpMyAdmin
body: <p>I'm trying to make a website that allows members to register. I've got a database set up with multiple tables. Simplified it looks like the following:</p>
  
  <p><strong>Users</strong> has two columns: 'ID' and 'Username', where 'ID' is the primary key.</p>
  
  <p><strong>Messages</strong> has two columns: 'ID' and 'Message', where 'ID' is a foreign key that refers to <strong>Users</strong>.</p>
  
  <p><strong>UserRank</strong> has several columns as well, including an 'ID' that is also a foreign key to <strong>Users</strong>. </p>
  
  <p>There's even more tables that use the same 'ID' to identify the user/member. </p>
  
  <p>I use MySQL to send and store the data from the webpage to the database like this:</p>
  
  <pre><code>$sqlQuery = "INSERT INTO users (Username) VALUES 
  ('$username')";
  $result=mysql_query($sqlQuery);
  </code></pre>
  
  <p><strong>Users</strong> gets filled like it should, but the 'ID' field of <strong>Messages</strong> and <strong>UserRank</strong> remains empty. I want to fill them accordingly, i.e. for every user in <strong>Users</strong> (who all have an unique ID due to it being a primary key), there should be a record in the other tables as well. </p>
  
  <p>I've tried to fill them manually with other queries but this doesn't seem to work:</p>
  
  <pre><code>$idQuery = mysql_query("SELECT ID FROM users WHERE Username='$username'");
  $result = mysql_fetch_array( $idQuery );
  $ID=$result['ID'];
  
  $query= "INSERT INTO Messages (ID) VALUES ('$ID')";
  $result=mysql_query($query);
  </code></pre>
  
  <p>I know it's a weird construction but I had to try <em>something</em>. Please point me in the right direction here.</p>