所以我的问题是发送数据到服务器与角度和post方法与PHP。 在服务器端单击提交按钮时,它添加了新的ID作为主键。但是来自输入的值不会被发送。感谢帮助。与角度和PHP的POST请求
我的HTML文件
<h1>{{name}}</h1>
<h1 id="number" ng-click="getNumber(1)">0</h1>
<form on-submit="addNew()">
<input type="text" ng-model="formModel.text" id="text" name="text"/>
<button ng-click="addNew()">Add new text</button>
</form>
角文件
app.controller('newCtrl', ['$scope','$http',function($scope,$http){
$scope.name = "Nikson";
document.getElementById('title').style.display = "none";
$scope.formModel = {};
$scope.addNew = function() {
console.log("Submited");
console.log($scope.formModel);
$http.post('post.php', $scope.formModel).
success(function(data){
console.log("ok")
}).error(function(data){
console.log("err");
});
};
}]);
而且finaly PHP文件
$conn = mysqli_connect('localhost','nemkeang','nemkic23', 'recs');
if(!$conn)
die("Error");
$text = $_POST['text'];
$sql = "INSERT INTO images (text)
VALUES ('$text')";
if (!mysqli_query($conn,$sql)) {
die('Error: ' . mysqli_error($conn));
}
echo "success";
mysqli_close($con);
[PHP中未定义角$ HTTP POST请求]的可能的复制(http://stackoverflow.com/questions/29936060/angular-http-post-request-undefined-in-php) – hurricane