-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathread.php
More file actions
80 lines (73 loc) · 2.26 KB
/
Copy pathread.php
File metadata and controls
80 lines (73 loc) · 2.26 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
<?php
// Check existence of id parameter before processing further
if (isset($_GET["id"]) && !empty(trim($_GET["id"]))) {
// Include config file
require_once "config.php";
// Prepare a select statement
$sql = "SELECT * FROM employees WHERE id = :id";
if ($stmt = $link->prepare($sql)) {
// Bind parameter
$stmt->bindValue(':id', trim($_GET["id"]), SQLITE3_INTEGER);
// Attempt to execute the prepared statement
$result = $stmt->execute();
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
// Retrieve individual field values
$name = $row["name"];
$address = $row["address"];
$salary = $row["salary"];
} else {
// URL doesn't contain a valid id parameter. Redirect to error page
header("location: error.php");
exit();
}
} else {
echo "Oops! Something went wrong. Please try again later.";
}
// Close statement
$stmt->close();
// Close connection (optional, SQLite auto-closes on script termination)
$link->close();
} else {
// URL doesn't contain id parameter. Redirect to error page
header("location: error.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>View Record</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
.wrapper{
width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h1 class="mt-5 mb-3">View Record</h1>
<div class="form-group">
<label>Name</label>
<p><b><?php echo $name; ?></b></p>
</div>
<div class="form-group">
<label>Address</label>
<p><b><?php echo $address; ?></b></p>
</div>
<div class="form-group">
<label>Salary</label>
<p><b><?php echo $salary; ?></b></p>
</div>
<p><a href="index.php" class="btn btn-primary">Back</a></p>
</div>
</div>
</div>
</div>
</body>
</html>