wesmith4 Posted June 24, 2013 Share Posted June 24, 2013 I am new at using PHP and MySQL. I am using a login.php script from Larry's book, and a similiar script I call view_coursegrades.php. I want to be able to identify a teacher who logs into my site, and then use a query based on that identification to allow them to edit and view grades in only the courses where they are the teacher. The following is some of the script: <?php # Script 12.12 - login.php #4 // This page processes the login form submission. // The script now stores HTTP_USER_AGENT value for added security. // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Need two helper files: require ('includes/login_functions.inc.php'); require ('./mysqli_connect.php'); // Check the login: list ($check, $data) = check_login($dbc,$_POST['email'], $_POST['pass']); if ($check) { // OK! // Set the session data: session_start(); $_SESSION['user_id'] = $data['user_id']; $_SESSION['first_name'] = $data['first_name']; // Store the HTTP_USER_AGENT: $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); // Redirect: redirect_user('loggedin.php'); } else { // Unsuccessful! // Assign $data to $errors for login_page.inc.php: $errors = $data; } mysqli_close($dbc); // Close the database connection. } // End of the main submit conditional. // Create the page: include ('includes/login_page.inc.php'); ?> ====================================== <?php # Script 10.1 - view_coursegrades.php #3 // This script retrieves the grades for courses. // This version links to edit and delete pages. session_start(); //Access the existing session. echo '<h2>The number below is for teacher ID.</h2>'; echo '<h2>{$_SESSION['user_id']}</h2>'; $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 COSID,LastName,FirstName,CourseTitle,TeaLastName, TeacherID, GradeEarned FROM TranscriptView"; $r = @mysqli_query ($dbc, $q); // Count the number of returned rows: $num = mysqli_num_rows($r); =================================== I have been unable to filter the query to select only records from the database where the TeacherID is for the teacher who logged in. Can anyone help me? Wes Smith Link to comment Share on other sites More sharing options...
margaux Posted June 24, 2013 Share Posted June 24, 2013 What about $q = "SELECT COSID,LastName,FirstName,CourseTitle,TeaLastName, TeacherID, GradeEarned FROM TranscriptView WHERE TeacherID = $_SESSION['user_id']"; Link to comment Share on other sites More sharing options...
Recommended Posts