問題檢查重複插入
之前我有一個表tbl_student_courses
其中加入2個表student
和courses
現在,當數據被插入它是2個IDS course_id
和student_id
組合。我只想在tbl_student_courses
中不會有這種組合的重複。
代碼
foreach($_POST['sel_course'] as $val) {
$query_std_course = "
INSERT INTO
`tbl_student_courses`
SET
`course_id` = '".$val."',
`std_id` = '".$_POST['std']."',
WHERE NOT EXISTS (
SELECT * FROM `tbl_student_courses` WHERE course_id=$val AND std_id=$std
)";
}
幫助
該查詢給SQL
語法錯誤。
任何機構可以幫助我嗎?
在此先感謝。
你缺少在內部查詢 – 2012-08-08 08:04:45
報價沒有問題相同。 – 2012-08-08 08:16:46