I want to know that the admin trying to add a user to a collection actually have created that user.
Explanation of variables:
$userid = the userid to be added to a collection
$ownerid = the admins userid
$collectionid = the collectionid the user should be added to.
IF ($userid in (SELECT id FROM ‘users’ WHERE ‘owner’ = $ownerid)) THEN INSERT INTO ‘collectionusers’
(‘collectionid’, ‘userid’) VALUES ($collectionid, $userid);
If I execute this it looks like this
IF (8 in (SELECT id FROM ‘users’ WHERE owner = 1)) THEN INSERT INTO ‘collectionusers’
(‘collectionid’, ‘userid’) VALUES (3, 8);
I have looked on:
11.3.2. Comparison Functions and Operators – IN()
I can’t figure out what’s wrong with this syntax.
You can do it using one query. For example:
Also, you can write a stored procedure.