Id not working

I seem to be getting this message and I am not sure why. I went to to look for a solution but it is not working with my coding.

can not get id
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ebermy5/public_html/login.php on line 43

This is my codes

ini_set ("display_errors", "1");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

/* Program: login.php
 * Desc:	Displays the new member welcome page. Greets
 *			member by name and gives a choice to enter
 *			restricted section or go back to main page.

$id = '';
$firstname = '';
$lastname = '';
$country = '';
$email = '';

if (isset($_SESSION['id'])) {
	 $id = $_SESSION['id'];
	echo "can not get id";

$id = mysql_real_escape_string($id);
 $result = mysql_query("SELECT id,firstname FROM `Members` WHERE $id={$_SESSION['id']}");

 while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    printf("id, firstname", $row[0], $row[1]);  

if ($firstname == ''){ //condition, is name equal to lower case firstname notice we use == and not =
	echo "Welcome, $firstname";
} else { //so incase the condition is not as expected
	echo "Sorry you are not $firstname";

<p>Your new Member accounts lets you enter the members only section
of our web site. You'll find special discounts, a profile of matches,
live advise from experts, and much more.</p>
<p>Your new Member ID and password were emailed to you. Store them
carefully for future use.</p>
<div style="text-align: center">
<p style="margin-top: .5in; font-weight: bold">
Glad you could join us!</p>
<form action="profile.php" method="post">
	<input type="submit"
		value="Enter the Members Only Section">
<form action="index.php" method="post">
	<input type="submit" value="Go to Main Page">

What am I missing.


$result = mysql_query(“SELECT id,firstname FROM Members WHERE $id={$_SESSION[‘id’]}”);

I dont like the curly-braces syntax, feel it leads to problems, but to each their own.

Also you might want to review [FPHP]printf[/FPHP], but that isnt the cause of this error message in particular.

Based on the error message, you are not getting the $id populated by $_SESSION[‘id’]. Keep in mind that session_id(); does not populated $_SESSION[‘id’];

I’m betting that if you echo( “SELECT id,firstname FROM Members WHERE $id={$_SESSION[‘id’]}” ); you are going to see this:

SELECT id,firstname FROM Members WHERE =

First, you don’t want to use $id to identify your database column, since you aren’t using $id to represent “id”. Second, there would be no point in setting $id = $_SESSION[‘id’] above only to use $_SESSION[‘id’] in your query, especially since you aren’t protecting $_SESSION[‘id’].

Your query should be:

“SELECT id,firstname FROM Members WHERE id=$id”

However, you still need to figure out why your $_SESSION[‘id’] is not being set prior to this page in your script.