Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysql_connect("localhost","root");
- if(!$con)
- {
- die('Could not connect:'.mysql_error());
- }
- @mysql_select_db("UniversityDB") or die("couldn't select database");
- session_Start();
- if(isset($_POST['usernameField']))
- {
- $_SESSION['username'] = json_encode($_POST['usernameField']);
- }
- $function = json_decode($_POST['functionID']);
- switch($function)
- {
- case 1:
- $password = json_encode($_POST['passwordField']);
- echo checkUser($_SESSION['username'],$password);
- break;
- case 2:
- echo getUsername($_SESSION['username']);
- break;
- case 3:
- echo getCourses($_SESSION['username']);
- break;
- }
- function checkUser($user,$password)
- {
- $query = "SELECT username, pass FROM account WHERE username = $user and pass = $password";
- $result = mysql_query($query);
- if(mysql_num_rows($result)>=1)
- {
- echo json_encode(true);
- }
- else
- {
- echo json_encode(false);
- }
- }
- function getUsername($user)
- {
- $query = "SELECT firstName FROM prof where username = $user";
- $result = mysql_query($query);
- $firstName = mysql_result($result,0,"firstName");
- echo json_encode($firstName);
- }
- function getCourses($user)
- {
- $query = "SELECT Distinct courseID ,courseName, creditHour, Description FROM course, prof, account WHERE prof.username = $user and prof.profID = course.profID";
- $result = mysql_query($query);
- $arr = array();
- while($record = mysql_fetch_assoc($result))
- {
- $arr[] = array ('courseName' => $record['courseName'],
- 'courseID' => $record['courseID'],
- 'creditHour' => $record['creditHour'],
- 'description' => $record['Description']);
- }
- echo json_encode($arr);
- }
- ?>
Add Comment
Please, Sign In to add comment