Using $_Session-values with mysql?
Posted: Wed Sep 21, 2011 3:19 pm
Hello.
I am having trouble using session-variables when they are needed to receive data from a table.
If I put the variable $FirstName, between single or double quotes in attempt to get some data from a table players, I get an error saying:
Parse error: syntax error, unexpected T_VARIABLE... on the code-line I've commented.
If I skip the quotes around the $FirstName, I get en error on the next code-line, stating:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.
Any ideas?
I am having trouble using session-variables when they are needed to receive data from a table.
If I put the variable $FirstName, between single or double quotes in attempt to get some data from a table players, I get an error saying:
Parse error: syntax error, unexpected T_VARIABLE... on the code-line I've commented.
If I skip the quotes around the $FirstName, I get en error on the next code-line, stating:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource.
Code: Select all
<?PHP
session_start();
//putting variables from the session-array into local variables
$FirstName = $_SESSION['GameName'][0];
$LastName = $_SESSION['GameName'][1];
$GameName = $FirstName . " " . $LastName;
echo "$GameName"; //this is echoing normally, indicating that the code is working so far.
//connecting to database
mysql_connect(****, *****, *****) or die(mysql_error());
mysql_select_db(****) or die(mysql_error());
//extracting data from the result-array
$result1 = mysql_query('SELECT Funds, Salory FROM Players WHERE FirstName="$FirstName" '); //here is some kind of trouble..
$row1 = mysql_fetch_array($result1);
echo $row1['Funds'];
echo $row1['Salory'];
?>