Error inserting data with Angular using $ http.post (). then

-3

I can not insert data into mysql using angularjs. The data is not sent to the insert.php file. I believe there is a $ http.post error that I do not know!

Any suggestions?

System: link

ScriptCode

//Metodoadicionar$scope.add=function(){//listar$scope.listProducts.push({id:$scope.id,name:$scope.name,price:$scope.price,quantity:$scope.quantity});/*inserirdadosnobanco*/$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();
?>
    
asked by anonymous 31.08.2017 / 19:02

1 answer

0
SQL syntax error = $ sql="INSERT INTO tprodutos ( id , name , price , quantity ) VALUES (NULL, '. $ name."', '" . $ '. ");";

    
31.08.2017 / 22:18