Id not working

I seem to be getting this message and I am not sure why. I went to php.net 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


<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
?>
<?php
session_start();
session_id(); 
?>
		
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
</head>

<body>
<?php
/* 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.
 */ 
include('Connections/connect_to_mysql.php'); 

$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>
<form action="index.php" method="post">
	<input type="submit" value="Go to Main Page">
	</form>		
		</div>
</body>
</html>

What am I missing.

:confused:

$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.