Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

LSL -> PHP -> MySQL not work, what I do wrong?

Theodor Ferraris
Registered User
Join date: 6 Feb 2007
Posts: 2
09-08-2007 07:13
I try to send some informations from SL to a MySQL WEB server, from witch I extract later and put in a WEB page.
I made a simple task, but it not work. Can anyone help me? Variables sanded from SL by llHTTPRequest do not enter in sql table. I listed here booth the LSL and the PHP script, and the result from mysql table. Data witch I put directly from PHP in db table appear OK, but data from LSL do not appear. Where I do wrong?

//-------------------
//SL object script:
//-------------------

// Conection and transfer to web MySQL server
key req_id2;
string lname;
default
{
state_entry()
{
llSetTimerEvent(10.0);
}

timer() {
llSetText("Stats...", <0.0,1.0,0.0>, 1);
}

http_response(key request_id, integer status, list metadata, string body) {
if (request_id == req_id2) {
llSay(0,"Transmision OK";);
llSay(0,body);
}
llSay(0,body); // for test
}

money(key id, integer amount)
{
lname = llKey2Name(id);
req_id2 = llHTTPRequest("http://slavalanche.3x.ro/conectsql.php", [HTTP_METHOD,"POST"], "name=" + lname + "&id=" + (string)id);
llSay(0,lname + (string)id);
}
}

//------------------------------------------------
// PHP script on web server (conectsql.php):
//------------------------------------------------

<?php

$username="user";
$password="pass";
$database="dbadress";
$db="dbname";

$name = $_POST['name'];
$key = $_POST['id'];
$azi = date("Y-m-d";);
$activat = $azi;
$table = "locatii";

$conexiune = mysql_connect($database,$username,$password);
mysql_select_db($db, $conexiune) or die( "Unable to select database";);

$query = "INSERT INTO `locatii` (`activat`, `locatie`, `proprietar`, `regiune`) VALUES ('".$activat."', '".$name."', '".$key."','Disneyland')";

mysql_query($query) or die(mysql_error());
mysql_close();
?>

//--------------------------------------------------
//The OUTPT line in table locatii from MySQL:
//--------------------------------------------------

Date: is the current date and is correct
Locatie : is empty – wrong
Proprietar : is empty – wrong
Regiune: ‘Disneyland’ – and is correct

and... I read posts about this subject founded here... but no resoult... :(
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
09-08-2007 11:49
Try running an echo(mysql_error()) to determine the error?

I can't see anything wrong off the bat--it looks good at an initial glance.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
09-08-2007 13:08
You might have to add the HTTP_MIMETYPE header, and set it to "application/x-www-form-urlencoded" before you can use POST.

I'm not able to verify this at the moment, but I believe that is a necessary prerequisite.

that would change this line
From: someone

req_id2 = llHTTPRequest( "Your URL here", [HTTP_METHOD,"POST"], params );

into:
From: someone

req_id2 = llHTTPRequest( "Your URL here", [HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"], params );


.
_____________________
Theodor Ferraris
Registered User
Join date: 6 Feb 2007
Posts: 2
YESSssssssssssss!!! It work!
09-09-2007 10:05
Tanks. You have right. Now it work!
Well... for people have the same problem: Use information from previews post. And the rest of the scripts is OK.
Now can go to next part of the project. :)