[英]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.