Jump to content


Photo

Query Question


  • Please log in to reply
3 replies to this topic

#1 alexcrosson

alexcrosson
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 01 October 2006 - 08:09 PM

OKay i have my database set up like so:

id        username              password                firstname              lastname
1          sample                    ck3949                John                      DOE

Someone can login and it checks weather its the right password and then redirects them to a diferent page. On that page I want to have a message Saying "Welcome John", meaning that i need to pull the firstname out of the row of the user that is logged in.

Heres my code:

$query = mysql_query("SELECT firstname FROM users WHERE username='$user'") or die ("Can't execute: " . mysql_error());
	$name = $query
?>
  <h1>Welcome <? print $name; ?>,</h1>

And i don't get any errors but my output is:

Welcome Resource id #4

Any idea?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 October 2006 - 08:43 PM

$name = mysql_result($query, 0);
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 alexcrosson

alexcrosson
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 01 October 2006 - 09:12 PM

Thanks that did the trick. but do u think you could explain it?


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 October 2006 - 10:50 PM

These can do that better

www.php.net/mysql_result

www.php.net/mysql_query
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users