1

我有以下问题。我正在使用 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 使用一些表单和表单域。

4

3 回答 3

1

当您使用 POST 时,您可以将数据作为字符串放在第三个参数中,如下所示:

llHTTPRequest("http://antima.freehostia.com/update.php", [HTTP_METHOD, "POST"],
   "12:23&here&This is a test of url&12");

将数据与 URL 一起放置时会遇到的一个问题是,它需要首先使用 llEscapeURL() 进行编码,但您不需要使用 POST 来执行此操作并将数据放在第三个参数中。

于 2011-07-30T06:03:16.630 回答
1

在您发送请求之前将 URL 回显给您自己,希望您能看到问题所在。您的 URL 是通过将字符串值连接在一起来组装的,而不是设置它以便将这些值分配给请求变量。

你想要做的可能看起来像:

    time = "12:23";
    address = "here";
    message = "This is a test of url";
    num_left = 12;
    url += "time=" + time;
    url += "&address=" + address;
    url += "&message=" + message;
    url += "&num_left=" + num_left;
于 2009-07-22T02:39:13.433 回答
0
$nome = $_POST['nome'];
$localizacao = $_POST['localizacao'];
$mensagem = $_POST['mensagem'];
于 2010-07-21T17:56:42.927 回答