PDA

View Full Version : Getting "Resource id #8" when trying to pull out data from a database?


nikee
02-07-2010, 12:53 PM
Hey. :)

I'm trying to get the value of the "admin" field in a table called "users". I can't see what's gone wrong, but something clearly isn't right. :eek:

mysql_connect("$connect_host", "$connect_username", "$connect_password") or die("Ooops! Det gick inte att ansluta till servern.<br />" . mysql_error());
mysql_select_db("$connect_db_name") or die("Det gick inte att välja databas :(" . mysql_error());

$checkUserAdmin = mysql_query("SELECT admin FROM users WHERE username='" . $_SESSION['username'] . "'");

echo $checkUserAdmin;When i echo it out, all i get is "Resource id #8", when i'm expecting a "0" or "1". The admin field is an int, if that matters..?

Thanks in advance :rolleyes:


EDIT: I forgot to mention that $_SESSION['username'] is the username of the currently logged in user. If i echo that out, i get the right username so i'm sure that's not the problem. :)

koko5
02-07-2010, 01:00 PM
Hi,

First you have to fetch array from mysql result resource not echoing itself.
Regards,
Nick

nikee
02-07-2010, 01:15 PM
Ow, right! :thumbsup: I forgot about that, hehe. I had a feeling it was something simple, like this.

However, it's still not working!

mysql_connect("$connect_host", "$connect_username", "$connect_password") or die("Ooops! Det gick inte att ansluta till servern.<br />" . mysql_error());
mysql_select_db("$connect_db_name") or die("Det gick inte att välja databas :(" . mysql_error());

$sql3 = mysql_query("SELECT admin FROM users WHERE username='" . $_SESSION['username'] . "'");

$checkUserAdmin = mysql_fetch_array($sql3);

echo $checkUserAdmin;Now when i echo it out, i just get "Array". :eek:


EDIT: Owh and here we go again, it does work! I just forgot to add ['admin'], like this: echo $checkUserAdmin['admin'];Thnx for the help :D