student_form.
html
<!DOCTYPE html>
<html>
<head>
<title>Student Record</title>
</head>
<body>
<h2>Student Record</h2>
<form action="student_insert.php" method="post">
Student ID: <input type="text" name="std_id"><br><br>
Student Name: <input type="text" name="std_name"><br><br>
Student Class: <input type="text" name="std_class"><br><br>
Student Age: <input type="text" name="std_age"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
student_insert.php
<?php
$conn = mysqli_connect("localhost", "root", "", "db_college");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$std_id = $_POST['std_id'];
$std_name = $_POST['std_name'];
$std_class = $_POST['std_class'];
$std_age = $_POST['std_age'];
$sql = "INSERT INTO tb_student (std_id, std_name, std_class, std_age)
VALUES ('$std_id', '$std_name', '$std_class', '$std_age')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
student_display.php
<?php
$conn = mysqli_connect("localhost", "root", "", "db_college");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM tb_student";
$result = mysqli_query($conn, $sql);
echo "<h2>Student Records</h2>";
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "ID: " . $row["std_id"]. " - Name: " . $row["std_name"].
" - Class: " . $row["std_class"]. " - Age: " . $row["std_age"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
database_setup.sql
CREATE DATABASE IF NOT EXISTS db_college;
USE db_college;
CREATE TABLE IF NOT EXISTS tb_student (
std_id INT PRIMARY KEY,
std_name VARCHAR(100),
std_class VARCHAR(50),
std_age INT
);