Do you see any issues with this MySQL query? It does not execute.
Any other better ideas?
INSERT INTO registration
( m_ID, e_ID, STATUS)
SELECT
:m_ID, :e_ID, 1
WHERE
EXISTS ( SELECT 1 FROM tableb WHERE ID = :e_ID)
AND EXISTS ( SELECT 1 FROM tablec WHERE m_ID = :m_ID)
Passing array with values for e_id and m_ID (PDO)
Basically the goal is to check if both IDs exists in different tables before inserting onto another table.
ERROR:
SQLSTATE[42000]: Syntax error or access violation: 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 'WHERE EXISTS ( SELECT 1 FROM tableb WHERE ID = '276') AND EX' at
line 4
Yet your query searches
tablebtwice. Unless you really meant “in a single different table” (and I don’t think so, you’d have used a singleEXISTS), then this might be the error you wanted.Also, PDO should have some sort of error logging. The query might not execute, but the reason should appear – or it should be possible to make it appear – somewhere.
UPDATE
I’m afraid I was wrong, the syntax is not correct. MySQL doesn’t allow
SELECT ... WHEREunless a table is specified.Try changing
in
TEST: