I have an array of values that I am looping through, trying to check a MySQL table for a column match for the array value, then inserting a new record if no match is found.
foreach($mls_ids as $mls_id) {
$query = "INSERT INTO mdc_data (mls_id) VALUES ('$mls_id')
WHERE NOT EXISTS ( SELECT mls_id FROM mdc_data WHERE mls_id = '$mls_id')
LIMIT 1 ";
$result = mysqli_query($mysqli, $query) or trigger_error("Query Failed!
SQL: $query - Error: ". mysqli_error($mysqli), E_USER_ERROR);
}
No records are inserted into an the table. (the table is empty)
Error thrown: 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 NOT EXISTS ( SELECT mls_id FROM mdc_data WHERE mls_id = '2189665') LIMIT