Codes
Codes
You’ll need a database to store information. Below is an example SQL code to create tables for students,
teachers, and courses.
sql
Copy code
USE school_management;
first_name VARCHAR(100),
last_name VARCHAR(100),
dob DATE,
gender VARCHAR(10),
email VARCHAR(100),
phone VARCHAR(15)
);
first_name VARCHAR(100),
last_name VARCHAR(100),
subject VARCHAR(100),
email VARCHAR(100),
phone VARCHAR(15)
);
course_name VARCHAR(100),
teacher_id INT,
);
Create PHP scripts to interact with the database. Below are examples for adding, displaying, updating,
and deleting students, teachers, and courses.
php
Copy code
<?php
$servername = "localhost";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
?>
php
Copy code
<?php
include('db.php');
if (isset($_POST['submit'])) {
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$sql = "INSERT INTO students (first_name, last_name, dob, gender, email, phone) VALUES
('$first_name', '$last_name', '$dob', '$gender', '$email', '$phone')";
?>
<form method="POST">
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select><br>
</form>
php
Copy code
<?php
include('db.php');
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "ID: " . $row["student_id"]. " - Name: " . $row["first_name"]. " " . $row["last_name"]. "<br>";
} else {
?>
php
Copy code
<?php
include('db.php');
if (isset($_GET['id'])) {
$student_id = $_GET['id'];
$result = $conn->query($sql);
$student = $result->fetch_assoc();
if (isset($_POST['submit'])) {
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$email = $_POST['email'];
$phone = $_POST['phone'];
} else {
?>
<form method="POST">
<select name="gender">
</select><br>
<input type="email" name="email" value="<?php echo $student['email']; ?>" required><br>
</form>
The front-end pages will include forms and tables to display and interact with student data.
CSS (styles.css)
css
Copy code
body {
margin: 0;
padding: 0;
background-color: #f4f4f4;
form {
background-color: #fff;
padding: 20px;
margin: 20px;
border-radius: 5px;
}
input[type="text"], input[type="email"], input[type="date"], select {
width: 100%;
padding: 10px;
margin: 5px 0;
border-radius: 5px;
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
button:hover {
background-color: #45a049;
4. Complete Example