将帖子内容存储到变量

时间:2017-02-08 21:08:27

标签: php sql httprequest

http请求代码

POST /parse.php HTTP/1.1
Host: mysite.com
Connection: Keep-Alive
Content-Length: 26
Content-Type: application/x-www-urlencoded

lt=12.123123&ln=123.123123

php code

//connect to database codes here
$database = "update name_tbl set lat='".$_GET['lt']."', lng='".$_GET['ln']."' where id=1";
mysqli_query($conn, $database)

所以我认为我的问题出在php部分,当我输入mysite.com/parse.php?lt=12.123123&ln=123.123123来测试它是否正常工作时它会发生但是当我发出http请求时 HttpRequest 上的代码,但发送值均为0.000000。

1 个答案:

答案 0 :(得分:0)

如果您不确定该请求是通过GET还是POST方式发送给您的,您可以尝试这样的

$lt = isset($_GET['lt']) ? $_GET['lt'] : (isset($_POST['lt']) ? $_POST['lt'] : null);
$ln = isset($_GET['ln']) ? $_GET['ln'] : (isset($_POST['ln']) ? $_POST['ln'] : null);

可能还有另一个名为$_REQUEST的选项,其中包含$_GET$_POST,但它也有自己的怪癖。请阅读以下链接以获得更好的主意:

Among $_REQUEST, $_GET and $_POST which one is the fastest?