解析错误:第51行的C:\ wamp \ www \ cas_pre_enrollment_scheduler_system \ sort_subject.php中的解析错误

时间:2017-02-07 08:34:22

标签: php mysql

请帮助如何解决这个问题需要论文谢谢

  

解析错误:第51行的C:\ wamp \ www \ cas_pre_enrollment_scheduler_system \ sort_subject.php中的解析错误

代码 -

if (isset($_POST['sort'])) {
    $year = $_POST['year'];
    $term = $_POST['term'];

    $courses = mysql_query("select * from course where code = '$course' LIMIT 1 ")or die(mysql_error());
    $course_id = mysql_fetch_array($courses)['course_id'];

    $user_query = mysql_query("select * from subject where course_id = $course_id and term = '$term' and year = '$year' ")or die(mysql_error());

    while($row1 = mysql_fetch_array($user_query)) {
        //$id=$row1['subject_id']; 
        //$course_id=$row1['course_id']; 

        $course_query = mysql_query("select * from course where course_id = $course_id ")or die(mysql_error());
        $course_row = mysql_fetch_array($course_query);
    }
}
?>

1 个答案:

答案 0 :(得分:0)

您的代码中几乎没有问题,其中任何一个都可以解决您的问题

  • while和if循环未关闭
  • 更改此代码,因为它可能不受支持

    $ course_id = mysql_fetch_array($ courses)[' course_id'];

  • 您的选择查询中$course_id缺少单引号

    我在下面进行了更改。试试这个

     if (isset($_POST['sort']))
        {
        $year = $_POST['year'];
        $term = $_POST['term'];
    
        $courses = mysql_query("select * from course where code = '$course' LIMIT 1 ")or die(mysql_error());
        $rw = mysql_fetch_array($courses);
    if($rw)
    {
        $course_id = $rw['course_id'];
    }
        //single quotes for $course_id
        $user_query = mysql_query("select * from subject where course_id = '$course_id' and term = '$term' and year = '$year' ")or die(mysql_error());
    
        while($row1 = mysql_fetch_array($user_query))
        {
            //$id=$row1['subject_id']; 
            //$course_id=$row1['course_id']; 
        //single quotes for $course_id
            $course_query = mysql_query("select * from course where course_id = '$course_id' ")or die(mysql_error());
            $course_row = mysql_fetch_array($course_query);
        }
     }
    ?>
    

我建议您进一步使用mysqliPDO数据库扩展名。