Ich versuche, ein JSON von einer Anwendung kommen und in der Datenbank gespeichert, versuche ich dies mit PHP und MySQL.Get json und speichern mit PHP
Ich brauche einen JSON und dann speichern Sie es auf der Bank. Ich kann JSON nicht bekommen und es auf eine Variable weitergeben. Speichern Sie die Variable in der Datenbank, die ich tun könnte.
Ich habe eine einfache Tabelle in der Bank erstellt und diese ich erstellt ist einfach, es ist nur zu lernen.
Receives_json.php
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE");
$assunto_contato = $_POST["assunto_contato"];
$comentario_contato = $_POST["comentario_contato"];
$nome_contato = $_POST["nome_contato"];
$data = date("Y-m-d H:i:s");
$conn = new mysqli("", "", "", "");
$sql_insert = "INSERT INTO contato VALUES ('$assunto_contato', '$comentario_contato', '$nome_contato', '$data')";
$stm = $conn -> prepare($sql_insert);
if ($stm->execute()){
$retorno = array("retorno" => 'YES');
} else {
$retorno = array("retorno" => 'NO');
}
echo json_encode($retorno);
$stm->close();
$conn->close();
?>
Ich erhalte json von AngularJS, dass AngularJS Funktion json Senden:
.controller('contatoController', function($scope, $stateParams, $ionicPopup, $ionicHistory, $http, $ionicPlatform, $state) {
$scope.contato = {};
$scope.Enviar = function() {
var linkContato = 'http://apps.greenonetec.com.br/insert_contato.php'
$http.post(linkContato, {
"assunto_contato": "$scope.contato.assunto",
"comentario_contato": "$scope.contato.comentario"
});
console.log()
$ionicHistory.nextViewOptions({
disableBack: true
})
$ionicPopup.alert({
title: 'Sua mensagem foi enviada'
}).then(function() {
$state.go('app.home');
})
console.log($scope.contato.assunto);
console.log($scope.contato.comentario);
}
})
Aber ich kann nicht die json bekommen, die von AngularJS in PHP kommt, Könnte mir jemand helfen?
Weiß jemand, was ich falsch mache in PHP? @ jesus-carrasco –
Weiß jemand, was ich falsch in PHP mache? @vivz –
Ihr js arbeitet jetzt? Welchen Fehler bekommst du jetzt? @ Lucas – Vivz