angularjs - 如何同时将数据保存到两个表中

I have a form which contains details of employee, including the basic details and educational details. How to save basic details in one table and educational details in another table?

The form is as below.

 <form name="empdetailsform">
  <h3>BASIC DETAILS</h3>

   <label>First Name</label>
   <input type="text" name="firstname" data-ng-model="empData.firstname"/></br>

   <label>Last Name</label>
   <input type="text" name="lastname" data-ng-model="empData.lastname" /></br>

   <label>Email</label>
   <input type="email" name="email" data-ng-model="empData.email"/></br>

    <label>Mobile</label>
    <input type="text" name="mobile" data-ng-model="empData.mobile"/></br>

     <label>City</label>
     <select name="city" data-ng-model="empData.city" >
       <option value="Hyderabad">Hyderabad</option>
       <option value="Bangalore">Bangalore</option>
       <option value="Chennai">Chennai</option>
      </select><br>

    <h3>Educational Details</h3>
      <button ng-click="addfield()">Add Education</button>
      <div ng-repeat="item in items">
      <input type="text" name="empData.qualification[]" placeholder="Qualification">
      <input type="text" name="empData.year[]" placeholder="Year of Passing">
      <input type="text" name="empData.percentage[]" placeholder="Percentage">
      </div> 
     <input type="submit" name="submit" ng-click="saveEmp()" />
      </form>

I want to save the basic details in employee table and the educational details in educational_details table. For which I have done the below coding using angular js and php

This is my ajax.php code in which I have saved the basic details

  if( isset($_POST['type']) && !empty($_POST['type'] ) ){
   $type = $_POST['type'];

   switch ($type) {
       case "save_user":
        save_user($mysqli);
        break;
    default:
        invalidRequest();
     }
    }else{
      invalidRequest();
     }

     function save_user($mysqli){
         $firstname=$_POST['user']['firstname'];
         $lastname=$_POST['user']['lastname'];
         $email=$_POST['user']['email'];
         $mobile=$_POST['user']['mobile'];
         $city=$_POST['user']['city'];
        $query = "INSERT INTO employees ( firstname, lastname, email, mobile, city) VALUES ('$firstname', '$lastname', '$email', '$mobile', '$city')";
    $mysqli->query( $query );
    $mysqli->close();
  }

I have done saving of basic details successfully. But I am not getting idea how to save the educational details in another table with empid which contains in employee table.

If the user enters 3 educational details then 3 the data must be saved in 3 records i.e, 3 rows in database. How do I do this using angularjs and php?

This is the jsFiddle link http://jsfiddle.net/b0jtqzpj/

Please help me

If angular is already posting all of the details that you need for all of the inserts, you can add another function to set up the different inserts and call each one when that post type is received. This should all be done on the server unless angular isn't sending all the required data, in which case the post request will need adjusting.

On the server the code will be similar to this:

if( isset($_POST['type']) && !empty($_POST['type'] ) ){
   $type = $_POST['type'];

   switch ($type) {
       case "save_user":
        save_user($mysqli);
        save_details($mysqli);
        break;
    default:
        invalidRequest();
     }
    }else{
      invalidRequest();
     }

function save_user($mysqli){

    $insert_sql = $mysqli->prepare("INSERT INTO employees ( firstname, lastname, email, mobile, city) VALUES (?,?,?,?,?)";
    $query->bind_param($firstname, $lastname, $email, $mobile, $city);

    $firstname=$_POST['user']['firstname'];
    $lastname=$_POST['user']['lastname'];
    $email=$_POST['user']['email'];
    $mobile=$_POST['user']['mobile'];
    $city=$_POST['user']['city'];

    $mysqli->query( $insert_sql );
    $mysqli->close();
}

function save_details($mysqli){

    $select_sql = $mysqli->prepare("SELECT id FROM employees WHERE email = ?");
    $select_sql->bind_param($email);

    $email=$_POST['user']['email'];

    $insert_sql = $mysqli->prepare("INSERT INTO educational_details ( employee_id, qualification, year, percentage) VALUES (?,?,?,?)";
    $query->bind_param($employee_id, $qualification, $year, $percentage);

    $employee_id = $mysqli->query( $select_sql );
    $qualification=$_POST['user']['qualification'];
    $year=$_POST['user']['year'];
    $percentage=$_POST['user']['percentage'];

    $mysqli->query( $query );
    $mysqli->close();
}