duanliaoyu8419 2017-04-13 20:04
浏览 47

离子发送空记录到mysql

I am trying to send data from my ionic app to mysql. The problem is when I click on the submit button, it actually post empty records in the database.

My HTML code

<form >
  <label class="item item-input">
    <span class="input-label">Product Name:</span>
    <input type="text" ng-model="productname">
  </label>
  <label class="item item-input">
    <span class="input-label">Product Price:</span>
    <input type="number" ng-model="productprice" >
  </label>
  <label class="item item-input">
    <span class="input-label" >Description:</span>
    <input type="text" ng-model="productdescription">
  </label>
  <input type="button" value="Submit" class="button button-assertive button-block" ng-click="submit()">
</form> 

The controller for the project

App.controller('appCtrl',  ['$scope', '$http', '$state, function ($scope, 
$http, $state, $ionicPopup, $timeout) {
  $scope.submit = function (){
    var link = "http://localhost/api.php";
    $http.post(link, {
       'productname' : $scope.productname,
        'productprice' : $scope.productprice,
        'productdescription' : $scopeproduct.description,
      }).success(function(response){

        $scope.pdata= response;
        console.log(response);

        //console.log(response);
      })
    }
   }]); 

This is my PHP code to post the the data to database

<?php  

    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");

    $conn = new mysqli("localhost", "root", "", "ionic");

    if ($conn->connect_error) {
        die("Connection failed: " .$conn->connect_error);
    } 

    $postdata = file_get_contents("php://input");

    if(isset($postdata) && !empty($postdata))
    {
    $request = json_decode($postdata);


    $pname = $request->productname;
    $pprice = $request->productprice;
    $pdescription = $request->productdescription;


     $sql = ("INSERT INTO `users` ( product_name, product_price, description) VALUES ('$pname', '$pprice', '$pdescription')");

      mysqli_query($conn, $sql);
  }

?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?