MyBB Community Forums

Full Version: SQL Syntax Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a table that has a field called friendlist. Early on in the code I run this query:
$query = $db->query("SELECT u.*, f.*, ug.* FROM ".TABLE_PREFIX."users u
			LEFT JOIN ".TABLE_PREFIX."fb f ON (u.uid=f.uid)
			LEFT JOIN ".TABLE_PREFIX."usergroups ug ON (u.usergroup=ug.gid)
			WHERE u.uid='{$mybb->input['uid']}' AND f.uid='{$mybb->input['uid']}'");
			$profile = $db->fetch_array($query);

A little further down in the code I do this:
if ($profile['friendlist']!=null)
		{
			$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid IN(".$profile['friendlist'].")");
			while ($friend = $db->fetch_array($query))
			{
				echo "<tr><td><a href='/forums/member.php?action=profile&amp;uid={$friend['uid']}' style='color:{$friend['namecolor']}>{$friend['username']}</a></td><td><img src='{$friend['avatar']}' alt='' height='50' width='50' /></td></tr>";
			} 
		}

It seems to be executing the code even though friendlist is null because I haven't added any values into it. All the other information it is grabbing from the first query is correct. What I am not doing correct with the second part?
error message Wrote:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Query:
SELECT * FROM mybb_users WHERE uid IN( )
Change the query with this;
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid IN('{$profile['friendlist']}')");
It worked now, but I'm confused as to why the statement executed in the first place.