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

リクエストを送信する前に 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 に答える
1

POST を使用すると、次のように、データを文字列として 3 番目の引数に入れることができます。

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

URL でデータを配置する際に発生する問題の 1 つは、最初に llEscapeURL() でエンコードする必要があることですが、POST ではその必要がなく、3 番目の引数にデータが含まれています。

于 2011-07-30T06:03:16.630 に答える
0
$nome = $_POST['nome'];
$localizacao = $_POST['localizacao'];
$mensagem = $_POST['mensagem'];
于 2010-07-21T17:56:42.927 に答える