/** * Get Student by ID from DB * @param Connection $connection * @param $id */ function getStudentById($connection, $id) { if (!$connection) { die('Could not connect: ' . mysql_error()); } else { echo 'Connected successfully !<br>'; $sqlQuery = "SELECT ID, LASTNAME, FIRSTNAME, ADDRESS FROM STUDENT WHERE ID = " . $id; echo "SQL query: {$sqlQuery} <br>"; mysql_select_db(DB_NAME_TEST); $retval = mysql_query($sqlQuery, $connection); if (!$retval) { die('Could not get data: ' . mysql_error()); } while ($row = mysql_fetch_array($retval)) { $id = $row[strtoupper(COLUMN_ID)]; $lastname = $row[strtoupper(COLUMN_LASTNAME)]; $firstname = $row[strtoupper(COLUMN_FIRSTNAME)]; $address = $row[strtoupper(COLUMN_ADDRESS)]; printStudentInfo($id, $lastname, $firstname, $address); } echo "Fetched data successfully !!\n"; } }
<?php require_once "header.php"; $userInfo = checkLogin("student"); printHeader("Student Panel"); printStudentInfo(); echo "<p>Welcome to the student panel!</p>"; echo "<a href='student_password.php'>Change password</a><br />"; echo "<a href='student_enroll.php'>Enroll in Classes</a><br />"; echo "<a href='student_drop.php'>Drop Classes</a>"; echo "<h2>My Classes</h2>"; echo "<table><tr><th>Class</th><th>Class Name</th><th>Semester</th><th>Grade</th></tr>"; $classList = $db->query("SELECT * FROM Takes NATURAL JOIN Class WHERE userId=(SELECT userId FROM User WHERE userName='******'username'] . "')"); while ($class = $classList->fetch_array(MYSQLI_ASSOC)) { echo "<tr><td><a href='student_grades.php?class=" . $class['classId'] . "'>" . $class['classNum'] . "</a></td><td>" . $class['className'] . "</td><td>" . $class['semester'] . " " . $class['year'] . "</td><td>" . $class['grade'] . "</td></tr>"; } echo "</table>"; printFooter("student");
<?php require_once "header.php"; $userInfo = checkLogin("student"); printHeader("Drop Classes"); $studentId = printStudentInfo(); if (isset($_POST['drop'])) { $dropId = $db->escape_string($_POST['drop']); $class = $db->query("SELECT classId FROM Takes NATURAL JOIN Class WHERE classId='{$dropId}' AND userId={$studentId} AND open=1"); if ($class->num_rows == 0) { echo "<p class='notice'>You are not enrolled in that class or it is not droppable.</p>"; } $db->query("DELETE FROM Takes WHERE classId='{$dropId}' AND userId={$studentId}"); $db->query("DELETE FROM AssignmentGrade WHERE classId='{$dropId}' AND studentId={$studentId}"); echo "<p class='notice'>You have dropped the class.</p>"; } $classList = $db->query("SELECT * FROM Takes NATURAL JOIN Class WHERE userId=(SELECT userId FROM User WHERE userName='******'username'] . "') AND open=1"); echo "<h1>Droppable Classes</h1>"; echo "<form action='student_drop.php' method='post'><table><tr><th>Class</th><th>Class Name</th><th>Semester</th><th>Drop</th></tr>"; while ($class = $classList->fetch_array(MYSQLI_ASSOC)) { echo "<tr><td>" . $class['classNum'] . "</td><td>" . $class['className'] . "</td><td>" . $class['semester'] . " " . $class['year'] . "</td><td><input type='radio' name='drop' value='" . $class['classId'] . "'></td></tr>"; } echo "<tr><td colspan='3'></td><td><input type='submit' value='Drop'></td></tr>"; echo "</table></form>"; printFooter("student");