0% found this document useful (0 votes)
2 views

HTML_PHP_Student_Assignment

The document consists of a web application for managing student records, including an HTML form for data entry, a PHP script to insert records into a MySQL database, and another PHP script to display the records. It also includes a SQL script for setting up the database and the student table. The application allows users to input student information such as ID, name, class, and age, and view all stored records.

Uploaded by

zaynabzaffar03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

HTML_PHP_Student_Assignment

The document consists of a web application for managing student records, including an HTML form for data entry, a PHP script to insert records into a MySQL database, and another PHP script to display the records. It also includes a SQL script for setting up the database and the student table. The application allows users to input student information such as ID, name, class, and age, and view all stored records.

Uploaded by

zaynabzaffar03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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
);

You might also like