SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Dreeass's Avatar
    Join Date
    Sep 2012
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question MySQL Query acting weird

    I've been working for quite a while with PHP and MySQL, and what is happening to me is very weird. I really don't know where it's coming from. So want I want is to check if the the user that is logged in ($user set in init.php) is an admin by checking his row in the database. So I do the following:
    Code:
    if(isset($user)) {
    		$query = mysql_query('SELECT group FROM users WHERE name = "'. $user .'"');
    		while($row = mysql_fetch_assoc($query)) {
    			echo $row['group'];
    		}
    }
    Which gives me the error that mysql_fetch_assoc is not getting the valid resource, so it gets false when it shouldn't. And when selecting and outputting something different then the row group it works fine. Here's how my database looks and the 2 users that are in it:

    t04yI.png
    6VY3L.png

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    GROUP is a reserved word in MySQL. Change the name of the column, or put it between backticks.

  3. #3
    SitePoint Enthusiast Dreeass's Avatar
    Join Date
    Sep 2012
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    GROUP is a reserved word in MySQL. Change the name of the column, or put it between backticks.
    Thanks, I tried dubble quotes and thought that that would work but this does. Thanks a lot!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •