简体   繁体   English

如何使用angularjs和PHP将数组输入值获取到数据库中

[英]how to get array input values into database using angularjs and PHP

I have a form in which on click of button input fields get appended. 我有一个表单,其中单击按钮输入字段后会附加该表单。 The form is as below. 形式如下。

<body data-ng-app="myApp" data-ng-controller="myController" >
<form name="educdetailsform" novalidate>
   <label>Education Details</label></br>
    <button ng-click="addfield()">Add Education</button>
     <div ng-repeat="item in items">
     <input type="text" name="qualification[]" data-ng-model="empData.qualification[]" placeholder="Qualification">
      <input type="text" name="year[]" data-ng-model="empData.year[]" placeholder="Year of Passing">
      <input type="text" name="percentage[]" data-ng-model="empData.percentage[]" placeholder="Percentage">
     </div> 
   <input type="submit" name="submit" ng-click="saveUser()" />
  </form>
</body>

The angular JS code for appending input fields is as follows 用于附加输入字段的有角JS代码如下

 var module=angular.module('myApp',[]);
 module.controller('myController',function($scope, $http){
  $scope.items = [{}];

$scope.addfield = function(){
   $scope.items.push({});
}

 });

This is the code and functionality http://jsfiddle.net/b0jtqzpj/2/ 这是代码和功能http://jsfiddle.net/b0jtqzpj/2/

How to get the fields to saveUser() function and then save the data into database table using PHP Like, if the user has entered 3 entries ie, the first entry must be saved in a row and 2nd entry in next row and 3rd entry in 3rd row. 如何获取字段以saveUser()函数,然后使用PHP Like将数据保存到数据库表中,如果用户输入了3个条目,即,第一个条目必须保存在一行中,第二个条目必须保存在下一行,第二个条目必须保存在第三排。 ie, if 3 entries are entered in html form and submitted, 3 entries must be created in database table. 即,如果以html形式输入3个条目并提交,则必须在数据库表中创建3个条目。

How do I catch data in angularjs saveUser() function and then save in database using PHP 如何在angularjs saveUser()函数中捕获数据,然后使用PHP保存在数据库中

您可以检查js小提琴http://jsfiddle.net/ss5yo9xk/4/进行ajax调用,您需要在php端使用以下代码来获取发布数据:

$postData = json_decode(file_get_contents('php://input'), true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM