-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_record.php
90 lines (83 loc) · 2.89 KB
/
search_record.php
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
88
89
90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Records Table</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ccc;
text-align: left;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
p {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Records Table</h1>
<?php
// Initialize variables for input data
$roll_number = '';
$error_message = '';
// Check if POST data is received
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize user input
$roll_number = filter_input(INPUT_POST, 'roll_number', FILTER_SANITIZE_STRING);
// Validate roll_number
if (!empty($roll_number)) {
try {
// Connect to SQLite database
$db = new PDO('sqlite:records.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Prepare SQL query to fetch records
$stmt = $db->prepare('SELECT * FROM students WHERE roll_number = :roll_number');
$stmt->bindParam(':roll_number', $roll_number);
$stmt->execute();
$records = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Display records in a table
if ($records) {
echo '<table>';
echo '<tr><th>Roll Number</th><th>Name</th><th>Date</th></tr>';
foreach ($records as $record) {
echo '<tr>';
echo '<td>' . htmlspecialchars($record['roll_number']) . '</td>';
echo '<td>' . htmlspecialchars($record['name']) . '</td>';
echo '<td>' . htmlspecialchars($record['date']) . '</td>';
echo '</tr>';
}
echo '</table>';
} else {
echo '<p>No records found for roll number ' . htmlspecialchars($roll_number) . '</p>';
}
} catch (PDOException $e) {
echo '<p>Database connection error: ' . $e->getMessage() . '</p>';
}
} else {
$error_message = 'Please enter a roll number to view records.';
}
} else {
$error_message = 'Access denied.';
}
// Display error message if any
if (!empty($error_message)) {
echo '<p>' . htmlspecialchars($error_message) . '</p>';
}
?>
<p><a href="search_record.html">Back to Search</a></p>
</body>
</html>