2
////Returns "loginSuccess=>true" if student login name and password is correct and list of course registrations the student is registered for, else "loginSuccess=>false";
3
////Parameters: loginName, password
4
////Returns loginSucces: true/false, array(courseName, courseOccasion)
6
//Prevents browsers (IE) from caching the response
7
header('Cache-Control: no-cache, must-revalidate');
8
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
9
header('Content-type: application/json; charset=utf-8');
11
include "dbconnect.php";
13
$queryString="SELECT Student.ssn
15
WHERE Student.loginName=:LOGINNAME
16
AND Student.passw=:PASSW;";
17
$stmt = $pdo->prepare($queryString);
18
$stmt->bindParam(':LOGINNAME', $_POST['loginName']);
19
$stmt->bindParam(':PASSW', $_POST['password']);
21
$count=$stmt->rowCount();
22
if($count==1){ //login successfull
23
$studentData=$stmt->fetch(PDO::FETCH_ASSOC);
24
$queryString="SELECT StudentCourseRegistration.courseName, StudentCourseRegistration.courseOccasion
25
FROM StudentCourseRegistration
26
WHERE studentSsn=:SSN;";
27
$stmt = $pdo->prepare($queryString);
28
$stmt->bindParam(':SSN', $studentData['ssn']);
30
$listOfCourseRegistrations=array();
31
$courseRegistrations=$stmt->fetchAll(PDO::FETCH_ASSOC);
32
foreach($courseRegistrations as $row){
33
array_push($listOfCourseRegistrations, array('courseName'=>$row['courseName'],'courseOccasion'=>$row['courseOccasion']));
35
echo json_encode(array('loginSuccess' => 'true','courseRegistrations'=>$listOfCourseRegistrations));
37
echo json_encode(array('loginSuccess' => 'false'));
b'\\ No newline at end of file'