I need some condition on insert statement to prevent unauthorized insertions.
I wrote something like this:

```
INSERT INTO `fund` (amount,description)
    SELECT 1000,'Some description'
    WHERE 12 IN (SELECT id FROM users WHERE allow_add=1)

```

Where 12 is the id of current user.
But mysql process stopped unexpectedly!
I use XAMPP with MySQL version: 5.5.5-10.1.13-MariaDB.
Note that I ran this code before this in SQL Server without any problem.
Any Idea?
['https://Stackoverflow.com/questions/46905636', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5259185/']
From users and Where exists work so maybe a bug with in?

```
MariaDB [sandbox]> delete from t where att = 3;
Query OK, 2 rows affected (0.04 sec)

MariaDB [sandbox]>
MariaDB [sandbox]> select * from t;
+------+------+
| id   | att  |
+------+------+
|    1 |    1 |
|    1 |    2 |
|    2 |    0 |
+------+------+
3 rows in set (0.00 sec)

MariaDB [sandbox]>
MariaDB [sandbox]> insert into t(id,att)
    -> select 4,3
    -> from users
    -> where id = 1;
Query OK, 1 row affected (0.05 sec)
Records: 1  Duplicates: 0  Warnings: 0

MariaDB [sandbox]>
MariaDB [sandbox]>
MariaDB [sandbox]> select * from t;
+------+------+
| id   | att  |
+------+------+
|    1 |    1 |
|    1 |    2 |
|    2 |    0 |
|    4 |    3 |
+------+------+
4 rows in set (0.00 sec)

MariaDB [sandbox]>
MariaDB [sandbox]> insert into t(id,att)
    -> select 4,3
    -> where exists (select 1 from users where id  = 1);
Query OK, 1 row affected (0.02 sec)
Records: 1  Duplicates: 0  Warnings: 0

MariaDB [sandbox]>
MariaDB [sandbox]> select * from t;
+------+------+
| id   | att  |
+------+------+
|    1 |    1 |
|    1 |    2 |
|    2 |    0 |
|    4 |    3 |
|    4 |    3 |
+------+------+
5 rows in set (0.00 sec)

```
It is not a proper way to authorize insertions in database. Instead, you can use programming based solution for this problem.

In PHP, a proper solution could be:-

```
if ($user->allow_add == 1){ //where $user is the User instance for current user
    $sql->query("INSERT INTO `fund` (amount,desc) VALUES(1000,'Some desc')");
}

```