-2

please help how to solve this problem need for thesis thank you

Parse error: parse error in C:\wamp\www\cas_pre_enrollment_scheduler_system\sort_subject.php on line 51

Code -

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);
    }
}
?>
Manoj Sharma
  • 1,467
  • 2
  • 13
  • 20
  • Which is line 51? Also, the while and if are both missing their } close brackets. – Dan Soper Feb 07 '17 at 08:37
  • 3
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Feb 07 '17 at 08:50
  • 2
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Have a look at what happened to [Little Bobby Tables](http://bobby-tables.com/) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Feb 07 '17 at 08:50
  • 1
    Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – GiamPy Feb 07 '17 at 08:51
  • I would guess this line `$course_id = mysql_fetch_array($courses)['course_id'];` and its use of `['course_id']` is not supported on your version of PHP – RiggsFolly Feb 07 '17 at 08:53
  • A thesis and you are using the `mysql_` database extension?? – RiggsFolly Feb 07 '17 at 08:54
  • $course_id = mysql_fetch_array($courses)['course_id']; – Esther Lopez Feb 07 '17 at 08:54

1 Answers1

0

There are few issues in your code, any one of which could solve your problem

  • while and if loop is not closed
  • change this code as it might not be supported

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

  • single quotes are missing for $course_id in your select queries

    I have made the changes below.Try this

     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);
        }
     }
    ?>
    

I suggest you to use mysqli or PDO database extensions further..

affaz
  • 1,191
  • 9
  • 23