我有以下问题。我正在使用 LSL 更新我的 mysql 数据库。数据库中有对应的表,并且有 update.php 的相应设置(已经用 html 表单和 php 测试过)。问题是添加了记录,但在适当的字段中没有值。
string time;
string address;
string message;
integer num_left;
integer listen_handle;
default
{
state_entry()
{
llSay(0,"Touch to insert messages into DB");
}
touch_start(integer total_number)
{
key owner = llGetOwner();
string name = llKey2Name(owner);
integer strlength = llStringLength(message);
string url = "http://antima.freehostia.com/update.php?";
float timing = llGetTime(); //Instead getting, and then resetting the time, we could use llGetAndReset() to accomplish the same thing.
llResetTime();
//time = (string)timing;
time = "12:23";
address = "here";
message = "This is a test of url";
num_left = 12;
url += time;
url += address;
url += message;
url += "12";
//url += (string)num_left;
llHTTPRequest(url, [HTTP_METHOD, "POST"], "");
}
}
更新
我已将代码更改为:
time = "12:23";
address = "here";
message = "This is a test of url";
num_left = 12;
url += "id" + id;
url += "&" + time;
url += "&" + address;
url += "&" + message;
url += "&" + "12";
但我在使用 POST 获取数据时遇到问题。在 PHP 端,我使用它来检索值:
$data = $_POST;
$var = explode("&", $data);
$time = $var[1];
$address=$var[2];
$message=$var[3];
$num_left=$var[4];
但是仍然有问题(我认为这次是 PHP 方面)并且添加了另一条空记录。我只需键入以下内容即可测试 LSL 提供的响应:
$data = "http://antima.freehostia.com/update.php?&12:23&here&This is a test of url&12";
它奏效了。
如何在不指定字段名称的情况下从 $_POST 获取整个字符串并将其存储在 $data 变量中?也许这很容易,但我找不到任何东西。大多数 PHP 使用一些表单和表单域。