Is there a way to add a value at the same time to MySQL table and to a list of AngularJS? Code works well, with button "submit" that adds to list the selected products with the exception of the insert into table of MySQL database. Is there any solution to do this? Thank you.
$scope.product = [{id: 1,name: "Pc",price: "1.50"}];
$scope.addToOrder = function (item, qty) {item.qty = 0;
$scope.order.push(item);
};
$scope.toggleChecked = function (index) {
$scope.checked.push($scope.order[index]);
$scope.order.splice(index, 1);
};
$scope.product_submit = function(submit_product){
$http.post("insert.php",{'prod_name': $scope.item.name, 'prod_price': $scope.item.price})
.success(function(data, status, headers, config){
console.log("inserted Successfully");
});
This is index.html
<li class="list-group-item" ng-repeat="item in order">
<tr ng-repeat="item in checked" class="table-responsive"></tr>
<div class="row">
<form name="add_product" method="POST">
<div type="text" class="col-md-4" >{{item.name}}</div>
<input data-ng-model="item.name" name="prod_name">
</div>
</li>
<button ngclick="toggleChecked($index);product_submit()"name="submit_product">Submit</button>
insert.php
$data = json_decode(file_get_contents("php://input"));
$pname = mysql_real_escape_string($data->prod_name);
$pprice = mysql_real_escape_string($data->prod_price);
mysql_connect("host", "user", "pass") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
mysql_query("INSERT INTO product (name,price) VALUES ('$pname','$pprice')");
Print "Your information has been successfully added to the database.";