I have a SQL insert statement that looks something like this?
$SQL = "INSERT INTO profile_answers (user_id, profile_id, question_id, question_answer, timestamp) VALUES ($user_id, $profile_id, {$i}, $answer, NOW())";
This is called three times, each time altering the question ID but the user_id and profile_id are the same. Is it possible to prevent duplicate entries using ‘ON DUPLICATE KEY UPDATE by first looking at the first two fields (user_id, profile_id)?
A entry in my DB would look like this:
user_id profile_id question_id
5 7 1
5 7 2
5 7 3
Is it possible to prevent a second insert of ( 5, 7, 1) for example?
This will prevent inserting the same values twice for these columns.