Experiment 11 dbms[1]
Experiment 11 dbms[1]
1 System 1
Implementation:-
1. Database Connection (db.php)
php
<?php
$servername = "localhost"; // Your server name
$username = "root"; // Your database username
$password = ""; // Your database password (leave empty if not set)
$dbname = "student_information_system"; // Your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
php
<?php include 'db.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Login</title>
</head>
<body>
<h2>Admin Login</h2>
<form method="POST" action="">
<label for="admin_name">Username:</label>
<input type="text" name="admin_name" required><br>
<label for="admin_pass">Password:</label>
<input type="password" name="admin_pass" required><br>
$stmt = $conn->prepare($sql);
$stmt->bind_param("ss", $admin_name, $admin_pass);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
echo "Login successful!";
// Redirect to add student page or dashboard here
// header("Location: add_student.php");
exit();
} else {
echo "Invalid username or password.";
}
}
$stmt->close();
$conn->close();
?>
</body>
</html>
3. Add Student (add_student.php)
php
<?php include 'db.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Student</title>
</head>
<body>
<h2>Add New Student</h2>
<form method="POST" action="">
<label for="roll_no">Roll No:</label>
<input type="number" name="roll_no" required><br>
<label for="name">Name:</label>
<input type="text" name="name" required><br>
<label for="age">Age:</label>
<input type="number" name="age"><br>
<label for="address">Address:</label>
<input type="text" name="address"><br>
<label for="section">Section:</label>
<input type="text" name="section"><br>
<label for="group_name">Group:</label>
<input type="text" name="group_name"><br>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$stmt = $conn->prepare($sql);
$stmt->bind_param("isssssssss",
$roll_no,
$name,
$age,
$address,
$dob,
$email_id,
$phno,
$course_enrolled,
$section,
$group_name);
if ($stmt->execute()) {
echo "New student added successfully!";
} else {
echo "Error: " . $stmt->error;
}