title: Selecting multiple data from a table and inserting into another table using PHP form
body: <p>I've created a form that submits data into multiple tables. My fields are First Name, Last Name, Email, City/Region/Country and they're all inserted into 3 different tables (User, Email, Location).</p>
  
  <p>The data goes into User and Email just fine, but I'm confused about what to do with Location.</p>
  
  <p>I have 3 separate tables for Location (City, Region, Country). What I want to do is insert CityID, RegionID, and CountryID into the Location table. I have the City/Region/Country field set up so it autocompletes based on the city like this:</p>
  
  <p><img src="https://i.stack.imgur.com/CYvJG.png" alt="http://i.stack.imgur.com/CYvJG.png"></p>
  
  <p>My Cities table has all the necessary info (CityID, RegionID, CountryID). How can I pull that data from the Cities table and insert it into my Location table?</p>
  
  <p>Here's part of my code. I'm very very new to PHP and MySQL, so I apologize for the sloppiness of this. The first part of the code works, but the 2nd part doesn't (inserting data into the Location table).</p>
  
  <pre><code>//Insert static values into people table
  $sql_user = sprintf("INSERT INTO User (FirstName, LastName,) VALUES ('%s','%s')",
                      mysql_real_escape_string($_POST['FirstName']),
                      mysql_real_escape_string($_POST['LastName']),
  $result_user = $db-&gt;query($sql_user);
  
  //get last inserted userid
      $inserted_user_id = $db-&gt;last_insert_id();
  
  //Insert values into location table
  $sql_city = sprintf("INSERT INTO Location (UserID, CityID, RegionID, CountryID) 
  VALUES ('$inserted_user_id',(SELECT CityID, RegionID, CountryID, FROM Cities))");
  $result_city = $db-&gt;query($sql_city);
  </code></pre>
  
  <p>I figure maybe I need to have "WHERE..." after FROM Cities, but I don't know what my condition would be.</p>