Resource id #2 ???

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nshah
Forum Newbie
Posts: 5
Joined: Wed Apr 14, 2004 11:08 pm

Resource id #2 ???

Post by nshah »

hey guys...

ok i have a database with ppls address fonenum faxnum email login and password

now when that user is logged in
it starts a session and assigns a variable for the users name
$_SESSION['user']
i know this variable contains the right information because when i use the echo statement it displays the user's name

however... when i want to display a specific row from my database on the page --with the following code

$result = mysql_query("SELECT * FROM register WHERE login ='$_SESSION['user']'");
echo $result;

--- the page displays "Resource id #2"

can anyone help?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You are missing one of the mysql_fetch_ functions after the query.
See http://php.net/mysql_query and http://php.net/mysql_fetch_assoc for examples.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

lol, we've all wondered this at some point.

basically you need to create an array for it,
continuing on your code

Code: Select all

$result = mysql_query("SELECT * FROM register WHERE login ='$_SESSION['user']'");
$array = mysql_fetch_array($result, MYSQL_ASSOC);
// now to print use $array['username'], $array['password'] etc etc
// you will need to make a loop to get all values
good luck
Post Reply