So I made this flash game and all appropriate variables are entered. If a user is logged in, it SHOULD enter the variable $_SESSION[user] into the mysql database to store the user’s score. For some strange reason, it doesn’t do that. What makes it even stranger is that I can echo the $_SESSION[user] variable correctly, but when thrown into a mysql DB, it returns NULL (as 0). Here’s the code that does all the processing.
<?php
session_start();
?>
<html>
<?php
include("../package.php"); //stuff for UI
echo $_SESSION[user]; //this works
if($_SESSION[user]){
mysql_query("INSERT INTO `DB`.`TABLE` (`user`,`type`,`game`,`score`) VALUES ('$_SESSION[user]', '$_POST[type]', '$_POST[g]', '$_POST[score]')");
?>
//Congratulations message in HTML
<?php
}
else{
?>
//Tells you to login (the 'else' statement to if($_SESSION[user])) also in HTML
<?php
}
?>
I don’t see anything wrong….
Change your logic to this, for debugging purposes:
That’ll give you the full text of the generated query, as well as the exact error message MySQL produced. If the query succeeds, then things continue as normal. If there was an error, then you’ll be told why.
Most likely the error is due to your mis-quoting of session values:
PHP’s polite and will translate your
$_SESSION[user]into$_SESSION['user'](note the quotes). But when you do this from within a double-quoted string, all bets are off.