-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_db.php
More file actions
67 lines (63 loc) · 1.98 KB
/
setup_db.php
File metadata and controls
67 lines (63 loc) · 1.98 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
<?php
// Set the content type to HTML
header('Content-Type: text/html; charset=utf-8');
// Include the database connection file
include 'db.php';
// SQL query to create the 'certificates' table if it doesn't exist
$sql = "CREATE TABLE IF NOT EXISTS certificates (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
code VARCHAR(10) UNIQUE NOT NULL,
status VARCHAR(20) DEFAULT 'issued',
issue_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (student_id) REFERENCES student(student_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
// Execute the query
if ($conn->query($sql) === TRUE) {
// On success, print a styled success message
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Database Setup Success</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f7f6;
margin: 0;
}
.container {
text-align: center;
padding: 40px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
h1 {
color: #27ae60;
font-size: 2.5rem;
}
p {
color: #555;
font-size: 1.1rem;
}
</style>
</head>
<body>
<div class="container">
<h1>✅ Database Updated Successfully!</h1>
<p>The `certificates` table is ready. You can now delete this file.</p>
</div>
</body>
</html>';
} else {
// On failure, print the error message
echo "Error creating table: " . $conn->error;
}
// Close the connection
$conn->close();
?>