如何将表列的行复制到另一个表列

时间:2013-09-08 04:36:01

标签: php mysql insert

我想从表exam_sections中复制多行并将其插入到exam_students.But我很困惑如何让它工作。我在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());


    }

1 个答案:

答案 0 :(得分: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'