无法使用离子从移动设备插入数据

时间:2019-02-16 19:13:27

标签: apache ionic-framework

我只是连接php mysql和ionic。有查询将离子数据从mysql插入到mysql中。从PC打开时没问题。但是当我从移动设备上使用它时没有任何结果。我已经将Access-Control-Allow-Origin添加到.htaccess文件,apache conf文件中,但是仍然无法从移动设备将数据插入到mysql中。您能帮助我哪里出问题了吗? 它是用户注册的php代码

      <?php
      header("Access-Control-Allow-Origin: *");
      if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
      }
      // Access-Control headers are received during OPTIONS requests
      if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { 
      if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
        header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
      if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
        header("Access-Control-Allow-Headers:
       {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
       exit(0);
       }
      require "dbconnect.php";  
      $data = file_get_contents("php://input");
      if (isset($data)) {
         $request = json_decode($data);
         $username = $request->username;
         $password = $request->password;
         $mobile = $request->mobile;
         $emailadd = $request->email;

         }

        $username = stripslashes($username); 
        $password = stripslashes($password);

        $sql = "INSERT INTO users (username, password, telephone, email)
        VALUES ('$username', '$password', '$mobile', '$emailadd')";

       if ($con->query($sql) === TRUE) {
       $response= "Registration successfull";

      } else {
      $response= "Error: " . $sql . "<br>" . $db->error;
      }
      echo json_encode($response); 
      ?>

可以在我的电脑上运行,但无法从移动设备上回复

0 个答案:

没有答案