<?php
$conn = new mysqli("localhost", "root", "Angel@1234", "testdb");
if ($conn->connect_error) die("Connection failed: " . $conn->connect_error);
$conn->query("CREATE TABLE IF NOT EXISTS admissions (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
phone VARCHAR(15) NOT NULL,
course VARCHAR(50) NOT NULL
)");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$stmt = $conn->prepare("INSERT INTO admissions (name, email, phone, course) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $_POST["name"], $_POST["email"], $_POST["phone"], $_POST["course"]);
$stmt->execute();
$stmt->close();
}
$result = $conn->query("SELECT * FROM admissions");
?>
<html>
<body>
<h2>College Admission Form</h2>
<form method="post">
<input type="text" name="name" placeholder="Name" required><br>
<input type="email" name="email" placeholder="Email" required><br>
<input type="text" name="phone" placeholder="Phone" required><br>
<input type="text" name="course" placeholder="Course" required><br>
<input type="submit" value="Apply">
</form>
<h2>Admission Records</h2>
<table border="1">
<tr><th>ID</th><th>Name</th><th>Email</th><th>Phone</th><th>Course</th></tr>
<?php while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['email']}</td>
<td>{$row['phone']}</td>
<td>{$row['course']}</td>
</tr>";
} ?>
</table>
</body>
</html>
<?php $conn->close(); ?>