-2
$id='2014104404';
$json_output = array();
$dbc = mysqli_connect($mysql_servername, $mysql_username, $mysql_password, $mysql_dbname) or die('Error connecting to MySql server');

$sql = "SELECT course_id, sections_id, rooms_id, start_time, end_time, day, studsched.schedule_id from schedule_tbl as sched,student_schedule_tbl as studsched where sched.schedule_id=studsched.schedule_id and student_id='$id' GROUP BY course_id, sections_id,sched_status='active';"
$result = mysqli_query($dbc, $sql); 
while($row = mysqli_fetch_assoc($result)){

    $json_output[] = $row;
}
echo json_encode($json_output);

It is fine and working when im pasting the sql query code in phpmyadmin, but when im trying to execute the php file it has an error: Parse error: syntax error, unexpected '$result' (T_VARIABLE).

Shadow
  • 33,525
  • 10
  • 51
  • 64
picolo
  • 41
  • 5

3 Answers3

2

You missed a semicolon or mispaced the semicolon after the query

$sql = "SELECT course_id, sections_id, rooms_id, start_time, end_time, day, studsched.schedule_id from schedule_tbl as sched,student_schedule_tbl as studsched where sched.schedule_id=studsched.schedule_id and student_id='$id' GROUP BY course_id, sections_id,sched_status='active';"

place semicolon after the query like below

$sql = "SELECT course_id, sections_id, rooms_id, start_time, end_time, day, studsched.schedule_id from schedule_tbl as sched,student_schedule_tbl as studsched where sched.schedule_id=studsched.schedule_id and student_id='$id' GROUP BY course_id, sections_id,sched_status='active'";
Anandhu Nadesh
  • 672
  • 2
  • 11
  • 20
0

add ; after this line

$sql = "SELECT course_id, sections_id, rooms_id, start_time, end_time, day, studsched.schedule_id from schedule_tbl as sched,student_schedule_tbl as studsched where sched.schedule_id=studsched.schedule_id and student_id='$id' GROUP BY course_id, sections_id,sched_status='active';"
Satya
  • 8,693
  • 5
  • 34
  • 55
0

You missed a semicolon on the line before creating $result. Moving forward, whenever you see an 'Undexpected variable' error, look at placing semicolons first.

Talking about this line of code:

$sql = "SELECT course_id, sections_id, rooms_id, start_time, end_time, day, studsched.schedule_id from schedule_tbl as sched,student_schedule_tbl as studsched where sched.schedule_id=studsched.schedule_id and student_id='$id' GROUP BY course_id, sections_id,sched_status='active';"

So replace the 'active';" at the end with 'active';";, notice the semicolon AFTER the quotation marks

InzeNL
  • 82
  • 1
  • 8