I’m having some difficulties with the LoadVars class.
This is a function that gets called on button press. When I run the movie the send_lv loadvars object traces
username=Anonymous&userid=0&preferenceVar=both&tagVar=&txtVar=%0D&titleVar=&longitudeVar=582&latitudeVar=1219
So the vars are filled. But they don’t seem to get passed on to sendReview as they don’t get inserted into my DBase. Also, the onLoad always returns ‘true’, whether I run it from my localhost or not. But the result_lv.debug remains undefined.
function sendReview(){
tagArray = tagVar.split(" ", 30);
trace(tagArray);
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
trace("success: " + result_lv.debug);
} else {
trace("Error connecting to server.");
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.latitudeVar = latitudeVar;
send_lv.longitudeVar = longitudeVar;
send_lv.titleVar = titleVar;
send_lv.txtVar = textVar;
send_lv.tagVar = tagArray;
send_lv.preferenceVar = preferenceVar;
if(isset(userid)){
// If authorised
send_lv.userid = userid;
send_lv.username = userName;
}else{
send_lv.userid = "0";
send_lv.username = "Anonymous";
}
trace(send_lv);
send_lv.sendAndLoad("sendReview.php", result_lv, "POST");
}
If wanted, this is my .php code.
<?php include("conn_settings.php");
if(isset($_POST['userid'])){
// Insert review
$tagid = uniqid(rand(0, 9), true);
$usr_id = addslashes($_POST['userid']);
$usr_name = addslashes($_POST['username']);
$latitude = addslashes($_POST['latitudeVar']);
$longitude = addslashes($_POST['longitudeVar']);
$title = addslashes($_POST['titleVar']);
$text = addslashes($_POST['textVar']);
$pref = addslashes($_POST['preferenceVar']);
/* Debug
$tagid = uniqid(rand(0, 9), true);
$usr_id = "0";
$usr_name = "Anonymous";
$latitude = 125;
$longitude = 250;
$title = "test";
$text = "database testje";
$pref = "onlyme";
*/
$query = "INSERT INTO `review` VALUES ('$tagid', '$usr_id', '$usr_name', '$latitude', '$longitude', '$title', '$text', '$pref');";
if(mysql_query($query)){
$debug = "Review added to database successfully.
";
}else{
$debug = "Review could not be added to database. " . mysql_error() . ".
";
}
// Loop through the tags array and create a row for each.
$tagQuery = "";
$tagArray = $_POST['tagVar']);
// $tagArray = array('Belgium', 'Ghent');
for($i=0; $i<count($tagArray); $i++){
$tagQuery = $tagQuery . "('$tagid','" . $tagArray[$i] . "'),";
}
$tagQuery = substr($tagQuery, 0, -1);
$query = "INSERT INTO `tag` VALUES $tagQuery;";
if(mysql_query($query)){
$debug = $debug . "Tags added to database successfully.";
}else{
$debug = $debug . "Tags could not be added to database. " . mysql_error() . ".";
}
echo "&debug=\"$debug\"";
}
?>
Also, when I use send_lv.send it just opens the .php script in my browser (as it would a .txt for example), without actually parsing it.
My thanks to anyone who can help me point out the problem. (also, I would like to apologize for cross-posting this here and on as.org, but it seems as.org’s somewhat died out :()