I've already read Passing an array to a query using a WHERE clause which is basically what I am doing, but with strings instead of integers. I am having an issue with the WHERE clause.
$codes_imp = "'" . implode("','", $codes) . "'";
$passwords_imp = "'" . implode("','", $passwords) . "'";
$comments_imp = "'" . implode("','", $comments) . "'";
$set_pass_query = "INSERT INTO users (password, comments) VALUES ($passwords_imp, $comments_imp) WHERE Code IN ($codes_imp)";
When executed, the query looks like this:
INSERT INTO users (password, comments)
VALUES ('password1', 'password2', 'password3', 'comment1', 'comment2', 'comment3')
WHERE Code IN ('code1', 'code2', 'code3')
All columns in the table are of type VARCHAR
. Clearly I have a syntax error (as it is telling me), but I am not sure how to construct this properly.