-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_info_delete.php
43 lines (38 loc) · 1.3 KB
/
fetch_info_delete.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
<?php
// Database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "infolinkdb";
try {
// Establishing a database connection
$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$regNumber = filter_var($_POST["regNumber"], FILTER_SANITIZE_STRING);
// Validate registration number if needed
// Check if the registration number exists
$stmt = $pdo->prepare("SELECT * FROM studentinfo WHERE id = :regNumber");
$stmt->bindParam(':regNumber', $regNumber);
$stmt->execute();
if ($stmt->rowCount() > 0) {
// Registration number exists, redirect to view.html with the data
header("Location: delete.html?regNumber=" . urlencode($regNumber));
exit();
} else {
// Registration number does not exist, redirect to error.html
header("Location: error.html");
exit();
}
}
} catch (PDOException $e) {
// Handle connection errors or other exceptions
header("Location: error.html");
exit();
} finally {
// Close the database connection
if (isset($pdo)) {
$pdo = null;
}
}
?>