-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstudent.php
More file actions
87 lines (63 loc) · 1.82 KB
/
student.php
File metadata and controls
87 lines (63 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/* student.php
Reads from a database
*/
// Turn on error reporting
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Connect to DB
require ($_SERVER['HOME'].'/connect.php');
$cnxn = connect();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>GRC Students</title>
</head>
<body>
<h1>GRC Students</h1>
<form method="get" action="student.php">
<input type="text" name="search">
<input type="submit" value="Search">
</form>
<?php
//1. Define the base query
$sql = "SELECT sid, first, last, advisor
FROM student";
echo "<p>GET:</p>";
var_dump($_GET);
//echo "<p>POST:</p>";
//var_dump($_POST);
if (isset($_GET['advisorid'])){
$advisorId = $_GET['advisorid'];
$sql .= " WHERE advisor = '$advisorId'";
}
else if (isset($_GET['search'])) {
$searchTerm = $_GET['search'];
$sql .= " WHERE sid LIKE '$searchTerm'
OR first LIKE '%$searchTerm%'
OR last LIKE '%$searchTerm%'";
}
echo "<p>$sql</p>";
//2. Send the query to the db
$result = mysqli_query($cnxn, $sql);
if (mysqli_num_rows($result) == 0) {
echo "<h2>No results found</h2>";
}
//3. Print the result
//var_dump($result);
foreach ($result as $row) {
//var_dump($row);
$sid = $row['sid'];
$last = $row['last'];
$first = $row['first'];
$advisor = $row['advisor'];
echo "<p>$sid - $first $last (Advisor: $advisor)</p>";
}
?>
</body>
</html>