【发布时间】:2016-09-25 13:30:20
【问题描述】:
希望你一切安好
我在html中有以下表格
<div class="table-responsive " >
<table class="table table-bordered">
<tr ng-repeat="x in [1, 2, 3, 4, 5]">
<td>
<td align="center">Price: <input name="price[]" type="number" ng-model="info.price[x]"/>
</td>
</tr>
</table>
</div>
我使用这个向插入函数提交数据:
ng-submit="addPrice(info)
这是我的功能:
$scope.addPrice= function(info){
info.price= [];
$http.post('../files/insert.php',{"price":info.price}).success(function(data){
if (data == true) {
}
});
}
在php文件中:
$data = json_decode(file_get_contents("php://input"));
$price[]=mysqli_real_escape_string($con, $data->price);
$query = "INSERT into myTbl (price) VALUES ('$price[0]')";
mysqli_query($con, $query);
如您所见,我正在尝试插入第一个价格输入,但无论我在输入中输入什么,它都会在数据库中插入 0!
问题出在哪里?!还是我做错了什么?
问候
【问题讨论】:
-
为什么要在发布之前重新初始化
info.price = []??以及您如何期望该数组中应该存在一些值? -
即使没有初始化,它仍然插入0
标签: php html angularjs forms http-post