-3
I cannot insert the data into mysql using Angularjs. The data is not sent to the Insert.php file. I believe there is an error $http.post that I am not aware of!
Any suggestions ?
System: http://crudangularjsphp.azurewebsites.net/index.html
Codigo Script
//Metodo adicionar
$scope.add = function(){
//listar
$scope.listProducts.push({
id:$scope.id,
name:$scope.name,
price:$scope.price,
quantity:$scope.quantity
});
/*inserir dados no banco*/
$http.post("insert.php", {
name:$scope.name,
price:$scope.price,
quantity:$scope.quantity})
.then(function(data,status,headers,config){
console.log("Data Inserted Successfully");
});
//limpar os inputs
$scope.id = '';
$scope.name = '';
$scope.price = '';
$scope.quantity = '';
};
PHP code
<?php
$HOST = "xxxxxxx";
$LOGIN = "xxxx";
$SENHA = "xxxxxx";
$db = "localdb";
mysql_connect($HOST, $LOGIN, $SENHA) or die("Não foi possível a conexão com o servidor");
mysql_select_db($db) or die("Não foi possível SELECIONAR o banco de dados");
$data = json_decode(file_get_contents("php://input"));
$name = mysql_real_escape_string($data->name);
$price = mysql_real_escape_string($data->price);
$quantity = mysql_real_escape_string($data->quantity);
$sql = "INSERT INTO tprodutos('name', 'price', 'quantity') VALUES('".$name."','".$price."','".$quantity."')";
$result = mysql_query($sql);
mysql_close();
?>
Test is here worked out, the only thing missing is you return the ID of the object that was created on the PHP server;
– Diogo Henrique Fragoso de Oliv
You need to at least tell me why you can’t.
– Jéf Bueno
The id is autocriment in mysql. I did not pass because it is created automatically
– alexjosesilva
Even if it is created automatically mysql manages to return the id, in real and good returns the entire Obejto, so the screen will represent the correct value of the database, without giving space for trickster pranks, rs
– Diogo Henrique Fragoso de Oliv
But I’m entering the data into the bank!
– alexjosesilva
Even making the corrections the error persists!
– alexjosesilva
Any more suggestions ?
– alexjosesilva