tags:

views:

321

answers:

4
+1  Q: 

lsl to mysql

Hi 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"], "");
    }
}
+1  A: 

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
A: 

Hi

Thank you for advice

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 php side I use 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.

Thank you.

niuchu
A: 

NVM found out the answer

niuchu
A: 

$nome = $_POST['nome']; $localizacao = $_POST['localizacao']; $mensagem = $_POST['mensagem'];

danilo