简体   繁体   English

$_SERVER["REQUEST_METHOD"] == "POST" 中未定义的索引

[英]Undefined index in $_SERVER["REQUEST_METHOD"] == "POST"

I have code with php, when I run then display an error message我有php代码,运行时显示错误信息

PHP Notice: Undefined index: esn /var/www/html/sat line 10 PHP 注意:未定义索引:esn /var/www/html/sat line 10

PHP Notice: Undefined index: lat /var/www/html/sat line 11 PHP 注意:未定义索引:lat /var/www/html/sat line 11

PHP Notice: Undefined index: lon /var/www/html/sat line 12 PHP 注意:未定义索引:lon /var/www/html/sat line 12

PHP Notice: Undefined index: status /var/www/html/sat line 13 PHP 注意:未定义索引:status /var/www/html/sat line 13

Each made the call http://domains.com/sat/index.php?esn=value1&lat=value2&lon=value3&status=value4 and the results of calling these parameters are always "NULL".每个调用http://domains.com/sat/index.php?esn=value1&lat=value2&lon=value3&status=value4并且调用这些参数的结果总是“NULL”。

We may be given a solution to this case.我们可能会得到解决这种情况的方法。 Thanks谢谢

below this source code error:下面这个源代码错误:

if ($_SERVER["REQUEST_METHOD"] == "POST") 
    {
      $postText=file_get_contents('php://input');
      //collect value of input field
      $esn = $_POST['esn'];
      $lat = $_POST['lat'];
      $lon = $_POST['lon'];
      $status = $_POST['status'];
      fwrite($postText);
      fclose($FileHandle);

      if ($postText) 
      {
         echo "Nomor ESN: ".$esn."<br>";
         echo "Latitude: ".$lat."<br>";
         echo "Longitude: ".$lon."<br>";
         echo "status: ".$status."<br>";
      }else{
         echo "NULL";
      }    
    }

您的数据,即使您通过表单发送,现在都在 URL 中,因此它们在 $_GET 中而不在 $_POST 数组中

You use GET method while you access data using Post method.您在使用 Post 方法访问数据时使用 GET 方法。 so you getting variable is null.所以你得到的变量为空。 Use bellow code for GET method使用以下代码获取 GET 方法

if ($_SERVER["REQUEST_METHOD"] == "GET") 
    {
      $postText=file_get_contents('php://input');
      //collect value of input field
      $esn = $_GET['esn'];
      $lat = $_GET['lat'];
      $lon = $_GET['lon'];
      $status = $_GET['status'];
      fwrite($postText);
      fclose($FileHandle);

      if ($postText) 
      {
         echo "Nomor ESN: ".$esn."<br>";
         echo "Latitude: ".$lat."<br>";
         echo "Longitude: ".$lon."<br>";
         echo "status: ".$status."<br>";
      }else{
         echo "NULL";
      }    
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未定义索引的php if($ _SERVER [&#39;REQUEST_METHOD&#39;] ==&#39;POST&#39;){找不到答案? - Undefined index php if ($_SERVER['REQUEST_METHOD'] == 'POST' ){ can't find answer? PHPUnit-未定义的索引:REQUEST_METHOD - PHPUnit - Undefined index: REQUEST_METHOD $ _SERVER [&#39;REQUEST_METHOD&#39;]以及同时POST和GET - $_SERVER['REQUEST_METHOD'] and simultaneous POST and GET 检查$ _SERVER [&#39;REQUEST_METHOD&#39;] ==&#39;POST&#39;的原因? - Reason for checking if $_SERVER['REQUEST_METHOD'] == 'POST'? $ _SERVER [“ REQUEST_METHOD”] ==“ POST”给出错误 - $_SERVER[“REQUEST_METHOD”] == “POST” giving error if($ _ SERVER [&#39;REQUEST_METHOD&#39;] ==“ POST”)遇到麻烦 - trouble with if($_SERVER['REQUEST_METHOD'] == “POST”) WordPress和处理if(($ _SERVER [“ REQUEST_METHOD”] ==“ POST”) - Wordpress and handling if (($_SERVER[“REQUEST_METHOD”] == “POST”) if($ _ SERVER [&#39;REQUEST_METHOD&#39;] ==&#39;POST&#39;)和android post请求不起作用 - if($_SERVER['REQUEST_METHOD']=='POST') and android post request not working isset($ _ POST [&#39;submit&#39;])vs $ _SERVER [&#39;REQUEST_METHOD&#39;] ==&#39;POST&#39; - isset($_POST['submit']) vs $_SERVER['REQUEST_METHOD']=='POST' !empty($ _ POST)与$ _SERVER [&#39;REQUEST_METHOD&#39;] ==&#39;POST&#39; - !empty($_POST) vs. $_SERVER['REQUEST_METHOD'] == 'POST'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM