データベースに新しい投稿を更新/作成するためにng-submitを使用しようとしています。私はこのHTMLを使用します。更新/登録とサービスの作成
<form ng-submit="savePost()">
<input ng-model="post.TASK">
<input ng-model="post.STATUS"">
<button type="submit"></button>
</form>
送信すると、この機能を持つコントローラに戻ります。私はconsole.log(scope.post.task)
を使用して、値の更新が機能するかどうかを示しますが、それは機能しますが、挿入倍率の値がどのようにサービス内にあるのかはわかりません。
$scope.savePost = function() {
console.log($scope.post.TASK);
//I send here ID but not sure if I can send multiples values
PostAPI.update($routeParams.id).success(function(data, status, headers, config) {
$scope.post = data;
});
}
})
私は更新するIDのみを取得します。
this.update = function(data) {
return $http.put("ajax/updatePost.php?postID=" + data);
}
これはphpファイルです。あなたはdata
があなたのリソースを更新するためにespecifyしなければならないPUT要求で
$conexion = new PDO("mysql:host=localhost;dbname=angularcode_task;charset=utf8", "root", "");
$postID = $_GET['postID'];
//WE NEED TASK AND STATUS HERE
$sql=$conexion->query("UPDATE tasks SET task='Buuu', status=2 WHERE id='$postID'");
$json = json_encode($sql->execute());
echo $json;