CSS Form

<?php
// MySQL Connection
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Create Database
$conn->query("CREATE DATABASE IF NOT EXISTS Academy3");
$conn->select_db("Academy3");

// Create Table
$conn->query("CREATE TABLE IF NOT EXISTS Student3 
(
    Student_ID INT AUTO_INCREMENT PRIMARY KEY,
    Student_Name VARCHAR(100) NOT NULL,
    Course VARCHAR(100) NOT NULL,
    Fees INT NOT NULL
)");

// INSERT
if (isset($_POST['insert'])) {
    $name = $_POST['name'];
    $course = $_POST['course'];
    $fees = $_POST['fees'];
    if ($name && $course && $fees) {
        $conn->query("INSERT INTO Student3 (Student_Name, Course, Fees) VALUES 
('$name', '$course', $fees)");
    }
}
// UPDATE
if (isset($_POST['update']))  
{ 
    $id = $_POST['id']; 
    $name = $_POST['name']; 
    $course = $_POST['course']; 
    $fees = $_POST['fees']; 
    if ($id && $name && $course && $fees) { 
        $conn->query("UPDATE Student3 SET Student_Name='$name', 
Course='$course', Fees=$fees WHERE Student_ID=$id"); 
    } 
} 

// DELETE
if (isset($_POST['delete']))  
{ 
    $id = $_POST['id']; 
    if ($id) { 
        $conn->query("DELETE FROM Student3 WHERE Student_ID=$id"); 
    } 
} 

// SEARCH
$search_result = null; 
if (isset($_POST['search']))  
{ 
    $id = $_POST['id']; 
    if ($id) { 
        $search_result = $conn->query("SELECT * FROM Student3 WHERE 
Student_ID=$id"); 
    } 
} 
?>
<!DOCTYPE html>
<html>
<head>
    <title>Student Management</title>
    <style>
        body {
            font-family: Arial;
            background: #f4f4f4;
            padding: 20px;
        }
        h2 {
            color: #333;
        }
        form {
            background: #fff;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0px 0px 8px rgba(0,0,0,0.1);
            max-width: 400px;
            margin-bottom: 30px;
        }
        input[type=text], input[type=number] {
            width: 100%;
            padding: 10px;
            margin: 8px 0 16px;
            border: 1px solid #ccc;
            border-radius: 6px;
        }
        input[type=submit] {
            background: #007bff;
            color: white;
            padding: 10px 16px;
            margin: 5px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
        }
        input[type=submit]:hover {
            background: #0056b3;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0px 0px 8px rgba(0,0,0,0.1);
        }
        th, td {
            padding: 12px;
            border-bottom: 1px solid #ddd;
            text-align: left;
        }
        th {
            background: #007bff;
            color: white;
        }
    </style>
</head>
<body>

<h2>Student Form</h2>
<form method="post">
    <label>ID (for update/delete/search):</label>
    <input type="number" name="id">

    <label>Name:</label>
    <input type="text" name="name">

    <label>Course:</label>
    <input type="text" name="course">

    <label>Fees:</label>
    <input type="number" name="fees">

    <input type="submit" name="insert" value="Insert">
    <input type="submit" name="update" value="Update">
    <input type="submit" name="delete" value="Delete">
    <input type="submit" name="search" value="Search">
</form>

<?php
// Show search result
if ($search_result && $search_result->num_rows > 0)  
{ 
    $row = $search_result->fetch_assoc(); 
    echo "<h3>Search Result:</h3>"; 
    echo "ID: " . $row["Student_ID"] . "<br>"; 
    echo "Name: " . $row["Student_Name"] . "<br>"; 
    echo "Course: " . $row["Course"] . "<br>"; 
    echo "Fees: " . $row["Fees"] . "<br>"; 
}
?>

<h2>All Students</h2>
<table>
<tr>
    <th>ID</th><th>Name</th><th>Course</th><th>Fees</th>
</tr>
<?php
$result = $conn->query("SELECT * FROM Student3"); 
while($row = $result->fetch_assoc())  
{ 
    echo "<tr>"; 
    echo "<td>".$row['Student_ID']."</td>"; 
    echo "<td>".$row['Student_Name']."</td>"; 
    echo "<td>".$row['Course']."</td>"; 
    echo "<td>".$row['Fees']."</td>"; 
    echo "</tr>"; 
}
?>
</table>

</body>
</html>

Output

Student Form

Student Form

All Students

Example row:
ID Name Course Fees
1 Quazi Ishaq PHP 5000