I am trying to run a script that produces a name from a query to a MySQL database:
PHP Code:
<?php
$sessionid = 'ne8295jskeuv03582je8ao2lf99sm3ng';
$query =
"SELECT users.First_name
FROM sessions
INNER JOIN users
ON sessions.UserID = users.UserID
WHERE sessions.SessionID = $sessionid ";
$con = mysql_connect ("mysql7.000webhost.com", "DELETED BY MODERATOR", "DELETED BY MODERATOR");
$db = mysql_select_db("DELETED BY MODERATOR",$con);
$result = mysql_query ($query);
while($row = mysql_fetch_array($result))
{
echo $row['First_name'];
}
?>
It involves using a php variable within the SQL query. When I replace this with the string itself it works fine, but when I try to do it with the variable in its place it says:
Quote:
|
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a5938807/public_html/test.php on line 25
|
What's going on? How do I put a variable into a query so that it is picked up properly as a string?