Jump to content
Larry Ullman's Book Forums

Recommended Posts

Code adapted from Larry Ullman's book, in chapters 10 through 12 (PHP and MYSQL).

 

<?php # Script 10.1 - view_coursegrades.php

// This script retrieves the grades for students.

// This version links to edit and delete pages.

// Session added 6/29/2013

Session_Start;

echo session_id();

echo "TeacherId=" . $_SESSION['user_id'];

$page_title = 'View Course Grades.';

include ('includes/header.html');

// echo '<h1>Course Grades at ASMWA</h1>';

 

require ('./mysqli_connect.php');

 

// Define the query:

$q = "SELECT StudentID, StudentIDfk, CourseID, CourseIDfk,COSID, LastName, FirstName, CourseTitle, Term, GradeEarned, Institution, TermYear, TermNumber, TeacherIDfk FROM CourseOfStudy, Courses, Students WHERE Students.StudentID = CourseOfStudy.StudentIDfk AND Courses.CourseID = CourseOfStudy.CourseIDfk AND TeacherIDfk = $_SESSION['user_id']";

$r = @mysqli_query ($dbc, $q);

 

When I run the script above, I get the following error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/00/10035700/html/view_coursegrades.php on line 15.

Line 15 is in red above (query).

 

The query works if a known number is used instead of the global variable: $_SESSION['user_id'].

There is something wrong involving the session variable for user_id, which is an integer.

 

If anyone can point out the error of my ways, I appreciate all assistance.

 

Wes Smith

 

Link to comment
Share on other sites

Try echoing $_SESSION['user_id'] out to the screen first, and make sure it contains the value you expect.

After that, trying wrapping the $_SESSION['user_id'] in the query in curly brackets, giving you the following:

$q = "SELECT StudentID, StudentIDfk, CourseID, CourseIDfk,COSID, LastName, FirstName, CourseTitle, Term, GradeEarned, Institution, TermYear, TermNumber, TeacherIDfk FROM CourseOfStudy, Courses, Students WHERE Students.StudentID = CourseOfStudy.StudentIDfk AND Courses.CourseID = CourseOfStudy.CourseIDfk AND TeacherIDfk = {$_SESSION['user_id']}";
  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...