dongmi9494 2016-01-22 20:56
浏览 36

使用已经涉及的按钮在MySQL表中发送AngularJS内容以在列表中推送$ scope项

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."; 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
    • ¥15 unity连接Sqlserver
    • ¥15 图中这种约束条件lingo该怎么表示出来
    • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
    • ¥15 流式socket文件传输答疑
    • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
    • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
    • ¥15 win10,这种情况怎么办
    • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
    • ¥100 在连接内网VPN时,如何同时保持互联网连接