次の問題があります。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 は、いくつかのフォームとフォーム フィールドを使用します。