1

I have the following problem. I'm updating my mysql database using LSL. There is a corresponding table in the database and there is update.php with appropriate settings (have tested it with html form and php). Problem is that the record is added but with no values in the appropriate fields.

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"], "");
    }
}

Update

I have changed the code to:

    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";

but I have a problem with getting the data using POST. On the PHP side I use this to retrieve values:

$data = $_POST;
$var = explode("&", $data);
$time = $var[1];
$address=$var[2];
$message=$var[3];
$num_left=$var[4];

however something is still wrong (I think this time with PHP side) and another empty record is added. I have tested the response provided by LSL by simply typing:

$data = "http://antima.freehostia.com/update.php?&12:23&here&This is a test of url&12";

and it worked.

How can I get the whole string from $_POST without specifying names of the fields and store it in the $data variable? Maybe it is something easy, but I could not find anything. Most of PHP uses some form and form fields.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
niuchu
  • 75
  • 10

3 Answers3

1

Echo the URL back to yourself before you send the requets and you'll hopefully see the problem. Your URL is being assembled by just concatenating the string values together, rather than setting it up so those values are assigned to request variables.

What you want to do probably looks like:

    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;
chaos
  • 122,029
  • 33
  • 303
  • 309
1

When you use POST you can put the data as a string in the third argument, like this:

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

One problem you would have with putting the data with the URL is that it would need to be encoded first with llEscapeURL(), but you don't need to do that with POST and having the data in the third argument.

ATL
  • 444
  • 6
  • 10
0
$nome = $_POST['nome'];
$localizacao = $_POST['localizacao'];
$mensagem = $_POST['mensagem'];
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
danilo
  • 1