I'm trying to get a json coming from an application and saved in the database, I'm trying to do this with php and mysql.
I need to get a json and then save it on the bank. I can not get json and pass it on some variable. Save the variable in the database I could do.
I created a simple table in the bank and this I created is simple, it's just to learn.
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();
?>
I'm getting json from angularjs, that angularjs function sending json:
.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);
}
})
But I can not get the json that is coming from angularjs in php, could anyone help me?