首页 > 解决方案 > 使用 php 输入类型参数发出 POST 请求?

问题描述

在这段代码中,我从另一台服务器获取 JSON 数据,并使用 PHP 表单进入该服务器,根据我的输入类型的名称,我创建了一些用作参数的对象,这样我就可以从 URL 和将它们保存到我的数据库中。问题是

   $token = stripslashes($_REQUEST["token"]);

它不起作用。我知道我的问题不清楚,但我只是不知道如何问它我做了我的研究,但我没有找到我想要的我希望你能帮助我。如果你有任何问题,请询问,我会尝试我最好解释一下。

 <html>
   <head>
  <meta charset="utf-8">
    <title></title>

 </head>
  <body >
  <?php

    require('db.php');
  $token = stripslashes($_REQUEST["token"]);
   $customerCode = stripslashes($_REQUEST["customerCode"]);
      $userName = stripslashes($_REQUEST["userName"]);
   $customerID = stripslashes($_REQUEST["customerID"]);
     $amount = stripslashes($_REQUEST["amount"]);}

     $url = 'xxxx.js';
     $data =json_encode(array('token' => $token,
             'customerCode' => $customerCode,
            'userName' =>$userName,
            'customerID' =>$customerID,
               'amount' =>$amount)
   );


   $options = array(
   'http' => array(
    'header'  => "Content-type: application/json\r\n",
    'method'  => 'POST',
    'content' => $data
  )  
   );
    $context= stream_context_create($options);
   $result = file_get_contents($url, false, $context);
  if ($result === TRUE) {
    $obj= json_decode($result,true);
     mysqli_query($conn,"INSERT INTO deposit 
(result, message, dictCount,guID,amount,customerCode,userName,dealerCode)


          mysqli_close($conn);
   }
    else{
      $obj= json_decode($result,true);
     mysqli_query($conn,"INSERT INTO deposit (result, message) VALUES



    mysqli_close($conn);

    }


    $obj= json_decode($result,true);
      var_dump($obj);




    ?>
    <form action = "xxxxxx.js" method = "post" name = "login" >
    <input type = "text" name="token" placeholder="token" required />
 <input type = "varchar" name="customerCode"placeholder="costumerCode" />
       <input type = "varchar" name="userName" placeholder="userName"  />
     <input type = "int" name="customerID" placeholder="customerID"  />
      <input type = "int" name="amount" placeholder="amount" required />
    <input name="submit" type = "submit" value="Log In"/>
    </form>

    </body>
   </html>

标签: phpjson

解决方案


推荐阅读