-1

我想从表exam_sections 中复制多行并将其插入exam_students。但我对如何让它工作感到困惑。我在 WHERE 子句中有错误。任何人都可以帮助我吗?顺便说一句,对不起我的英语不好。

这是我的代码:

if(isset($_POST['Add'])){
    session_start();
    $year = $_POST['year'];
    $course = $_POST['course'];
    $block = $_POST['block'];
    $examinergroupid = $_SESSION['usergroupid'];
    $subject_id = $_SESSION['subject_id'];

    $add = mysql_query("
INSERT INTO 
exam_students (stud_valid_nos, stud_email, stud_subject_id, stud_group_id )
SELECT 
exam_sections.sec_id_num,
exam_sections.sec_email, 
'$subject_id','$examinergroupid'  
WHERE exam_sections.sec_year = '$year'
AND exam_sections.sec_course = '$course'
AND exam_sections.sec_block = '$block'")
or die(mysql_error());


    }
4

1 回答 1

0

尝试:

INSERT INTO 
    exam_students (stud_valid_nos, stud_email, stud_subject_id, stud_group_id )
SELECT 
    sec_id_num,
    sec_email, 
    '$subject_id',
    '$examinergroupid'
FROM exam_sections
WHERE sec_year = '$year'
    AND sec_course = '$course'
    AND sec_block = '$block'
于 2013-09-08T04:46:58.610 回答