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