Author Topic: User Database Question  (Read 2440 times)

wiseman11

  • Beginner
  • *
  • Posts: 27
User Database Question
« on: October 23, 2009, 01:09:08 am »
    $CurrUser = $_SESSION['auth']['username'];
    echo "Curr user is: ".$CurrUser;
    $db = new ps_DB;
    $q = 'SELECT `username` FROM `#__users` WHERE `username`='.$CurrUser;
    $db->query( $q );
    $db->next_record();

Is there anything wrong with this query? I'm trying to get user information from the database, but when I changed my SQL statement to have a WHERE clause, it failed. I really want to populate some fields with current user information if possible

Sparky9292

  • Beginner
  • *
  • Posts: 29
Re: User Database Question
« Reply #1 on: December 31, 2009, 23:59:03 pm »
    $CurrUser = $_SESSION['auth']['username'];
    echo "Curr user is: ".$CurrUser;
    $db = new ps_DB;
    $q = 'SELECT `username` FROM `#__users` WHERE `username`='.$CurrUser;
    $db->query( $q );
    $db->next_record();

Is there anything wrong with this query? I'm trying to get user information from the database, but when I changed my SQL statement to have a WHERE clause, it failed. I really want to populate some fields with current user information if possible

Why not simply do?

Code: [Select]
$user =& JFactory::getUser();
// get username and name of user
$username = $user->get('username');
$name     = $user->get('name');

wiseman11

  • Beginner
  • *
  • Posts: 27
Re: User Database Question
« Reply #2 on: January 10, 2010, 10:51:18 am »
That makes much more sense than what I did...I found it elsewhere before now, but thanks :)