wesmith4 Posted June 30, 2013 Share Posted June 30, 2013 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 More sharing options...
HartleySan Posted June 30, 2013 Share Posted June 30, 2013 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']}"; 1 Link to comment Share on other sites More sharing options...
margaux Posted July 1, 2013 Share Posted July 1, 2013 Session_Start; session_start is a function so you need the brackets. I'm not sure if it needs to be in all lower case, but it is better practice. session_start(); Link to comment Share on other sites More sharing options...
wesmith4 Posted July 1, 2013 Author Share Posted July 1, 2013 Wow, Margaux! That fixed it. Thank you so much. Wes Link to comment Share on other sites More sharing options...
Recommended Posts