I'm trying to update a field in my database based on a variables value that comes from a Flash script. It seem to work just fine at first glace but for some weird reason the value is set to 0 in the database afterwards. I have no clue as to why it would do that.
Basically I'm trying to store where the user exited a particular project made in Flash. I have some code in Flash that will send the username and the lastSlide variable to a PHP-script.
My Flash code is like this:
Code: Select all
this.stop();
// ---
// PHP file
// ---
_global.php_file = "user.php";
// set up LSO
local_data = SharedObject.getLocal("loggedInUser", "/");
// take the username and store it in the LSO for later use.
loggedInUser = local_data.data.username;
// grab the current slide
slideNo = _root.rdinfoCurrentSlide;
myVars2 = new LoadVars();
myVars2.username = loggedInUser;
myVars2.slideNumber = slideNo;
myVars2.action = 'bookmark';
myVars2.sendAndLoad(php_file, myVars2, 'POST');
myVars2.onLoad = function()
{
if(this.error != undefined)
{
status_txt.text = this.error;
} else {
status_txt.text = this.error;;
}
}
My PHP code looks like this: (I cut out the other functions that work fine)
Code: Select all
<?
require_once('conf.inc.php');
require_once('functions.php');
// ----
// bookmark / resume function
// ----
function bookmark($username,$slideNumber)
{
GLOBAL $db, $table;
$username = trim($username);
$slideNumber = trim($slideNumber);
$query = @mysql_query("UPDATE $table SET lastSlide = $slideNumber WHERE userName = '$username'");
if(!$query)
{
return "error=" . mysql_error();
} else {
return "user=Bookmark set";
}
}
if(isset($HTTP_POST_VARS["action"]))
{
switch($HTTP_POST_VARS["action"])
{
case "register":
$result = register($HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass'],$HTTP_POST_VARS['email'],$HTTP_POST_VARS['question'],$HTTP_POST_VARS['answer']);
print $result;
break;
case "login":
$result = login($HTTP_POST_VARS['username'],$HTTP_POST_VARS['pass']);
print "user=" . $result;
break;
case "forget":
$result = forget($HTTP_POST_VARS['email']);
print $result;
break;
case "new_password":
$result = new_password($HTTP_POST_VARS['username'],$HTTP_POST_VARS['email']);
print $result;
break;
case "bookmark":
$result = bookmark($HTTP_POST_VARS['username'],$HTTP_POST_VARS['slideNumber']);
print $result;
break;
}
}
?>My database setup is like this:
Code: Select all
Feltnavn Datatype Nulværdi Standardværdi
userID int(20) Nej
userName varchar(15) Nej 0
userPassword varchar(32) Nej 0
userMail varchar(255) Nej
userQuestion varchar(255) Nej
userAnswer varchar(255) Nej
courseCompleted varchar(15) Nej
quizScore int(10) Nej 0
dateCompleted varchar(15) Nej
dateStarted varchar(15) Nej
lastSlide int(10) Nej
I'm not exactly a PHP guru but I tried for the last 5 hours trying to figure out what goes wrong. I tried saving the value as an INT, a string, in a different field of the database, using the intval() etc..
Anyone that can see what I did wrong and point me in the right direction?
Best regards,
Michael