-2

I got an Error while trying to convert my database.

Fehler in 163 - 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 2 Query war : SELECT * FROM phpbb_users WHERE user_active = 1 AND user_id NOT IN ()

My Code:

$e0 = query("SELECT * FROM ".$phpbb_prefix."_users
    WHERE user_active = 1 AND user_id NOT IN (".implode("','", $ilch_to_phpbb).")" , $phpbb_con)
    or die('Fehler in '. __LINE__ . ' - '.mysql_errno($phpbb_con) . ' : '. mysql_error($phpbb_con).'<br /> Query war : ' . $lastquery . '<hr />');

I can not recognize the error. Any Ideas?

  • Database: MySQL(i) 5.5.53-0+deb7u1
  • PHP: 5
FirstOne
  • 6,033
  • 7
  • 26
  • 45
  • 1
    Well, the `in` clause is empty, which isn't valid syntax in any database... – Mureinik Apr 23 '17 at 17:23
  • 1
    Possible Duplicate: [How to manage empty IN sql query?](http://stackoverflow.com/questions/10481334/how-to-manage-empty-in-sql-query) – FirstOne Apr 23 '17 at 17:23
  • 1
    Possible duplicate of [How to manage empty IN sql query?](http://stackoverflow.com/questions/10481334/how-to-manage-empty-in-sql-query) – cosmoonot Apr 24 '17 at 04:40

1 Answers1

0

The problem is with your implode. Imagine if $ilch_to_phpbb contains 2 user id's, the query will be:

SELECT * FROM ".$phpbb_prefix."_users
WHERE user_active = 1 AND user_id NOT IN (2','3)

That's obviously invalid SQL syntax.

You either need to drop the ' in the implode (although this will cause a SQL error if $ilch_to_phpbb is empty, because NOT IN () is invalid SQL), or add ' around it in the query:

AND user_id NOT IN ('".implode("','", $ilch_to_phpbb)."')
rickdenhaan
  • 10,857
  • 28
  • 37
  • `WHERE user_active = 1 AND user_id NOT IN ('".implode("','", $ilch_to_phpbb)."')" , $phpbb_con)` causes: Fehler in 163 - 1054 : Unknown column 'user_active' in 'where clause' Query war : SELECT * FROM phpbb_users WHERE user_active = 1 AND user_id NOT IN ('') – Beliar_666 Apr 23 '17 at 17:34
  • That's a different problem. That means there is no column "user_active" in your "phpbb_users" table. – rickdenhaan Apr 23 '17 at 17:35
  • Thanks. Problem solved now. Last error was caused by phpbb3. There is no Column User_active. There now is User_Type. 0 for active, 1 for inactive 2 for ignore and 3 for founder. – Beliar_666 Apr 23 '17 at 18:03