PHP Assignment (My) (1) 3
PHP Assignment (My) (1) 3
Create Php Web Pages for Employees Registration form with following
fields: Employee Name, Employee Number, Designation, Mobile no,
Salary, Gender, email id, address, hoto, username, password, confirm
password, Resume . Details should be edit, Delete and View with
appropriate validations. Also apply proper design accordingly and display
all the details employee number wise.
Db1.php
<?php
// Create connection
$conn = mysqli_connect("localhost", "root", "root", "mystore");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
Table1.php
<?php
// Connect to the database
$conn = mysqli_connect("localhost", "root", "root");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
register_employee1.php
<?php
// Database connection
$conn = new mysqli('localhost', 'root', 'root', 'php');
// Validations
if (empty($emp_name) || empty($emp_number) || empty($email) ||
empty($password) || $_POST['password'] !=
$_POST['confirm_password']) {
echo "Please fill all required fields correctly.";
} else {
// File upload for resume and photo
move_uploaded_file($_FILES['resume']['tmp_name'],
"uploads/resumes/$resume");
move_uploaded_file($_FILES['photo']['tmp_name'],
"uploads/photos/$photo");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Employee Registration</title>
<style>
/* Add some styling */
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
display: flex;
flex-direction: column;
width: 400px;
margin: auto;
}
input, select, textarea {
margin-bottom: 10px;
padding: 10px;
}
</style>
</head>
<body>
<h2>Register Employee</h2>
<form method="POST" enctype="multipart/form-data">
<input type="text" name="emp_name" placeholder="Employee
Name" required>
<input type="number" name="emp_number"
placeholder="Employee Number" required>
<input type="text" name="designation" placeholder="Designation"
required>
<input type="text" name="mobile" placeholder="Mobile No"
required>
<input type="number" step="0.01" name="salary"
placeholder="Salary" required>
<select name="gender" required>
<option value="">Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
<input type="email" name="email" placeholder="Email ID"
required>
<textarea name="address" placeholder="Address"
required></textarea>
<input type="file" name="photo" accept="image/*" required>
<input type="file" name="resume" accept=".pdf,.docx" required>
<input type="text" name="username" placeholder="Username"
required>
<input type="password" name="password" placeholder="Password"
required>
<input type="password" name="confirm_password"
placeholder="Confirm Password" required>
<button type="submit">Register</button>
</form>
</body>
</html>
View_employees.php
<?php
$conn = new mysqli('localhost', 'root', 'root', 'php');
// Fetch employees
$result = $conn->query("SELECT * FROM employees ORDER BY
emp_number ASC");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>View Employees</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<h2>Employee List</h2>
<table>
<thead>
<tr>
<th>Employee Number</th>
<th>Name</th>
<th>Designation</th>
<th>Mobile</th>
<th>Salary</th>
<th>Gender</th>
<th>Email</th>
<th>Address</th>
<th>Photo</th>
<th>Resume</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr>
<td><?= $row['emp_number'] ?></td>
<td><?= $row['emp_name'] ?></td>
<td><?= $row['designation'] ?></td>
<td><?= $row['mobile'] ?></td>
<td><?= $row['salary'] ?></td>
<td><?= $row['gender'] ?></td>
<td><?= $row['email'] ?></td>
<td><?= $row['address'] ?></td>
<td><img src="uploads/photos/<?= $row['photo'] ?>"
width="50" alt="photo"></td>
<td><a href="uploads/resumes/<?= $row['resume'] ?>">View
Resume</a></td>
<td><a href="edit_employee.php?id=<?= $row['emp_id']
?>">Edit</a></td>
<td><a href="delete_employee.php?id=<?= $row['emp_id'] ?>"
onclick="return confirm('Are you sure?')">Delete</a></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
Edit_employee.php
<?php
$conn = new mysqli('localhost', 'root', 'root', 'php');
if (isset($_GET['id'])) {
$emp_id = $_GET['id'];
$sql = "DELETE FROM employees WHERE emp_id=$emp_id";
Table2.php
<?php
// Connect to the database
$conn = mysqli_connect("localhost", "root", "root");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
Add_customer.php
<?php
// Database connection
$conn = new mysqli('localhost', 'root', 'root', 'php');
// Validation
if (empty($name) || empty($contact_no) || empty($email) ||
empty($dob)) {
echo "Please fill all the required fields.";
} else {
// Upload address proof image
move_uploaded_file($_FILES['address_proof']['tmp_name'],
"uploads/address_proofs/$address_proof");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Add New Customer</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
display: flex;
flex-direction: column;
width: 400px;
margin: auto;
}
input, textarea {
margin-bottom: 10px;
padding: 10px;
}
</style>
</head>
<body>
<h2>Add New Customer</h2>
<form method="POST" enctype="multipart/form-data">
<input type="text" name="name" placeholder="Customer Name"
required>
<textarea name="address" placeholder="Address"
required></textarea>
<input type="text" name="contact_no" placeholder="Contact No"
required>
<input type="date" name="dob" required>
<input type="email" name="email" placeholder="Email ID"
required>
<input type="file" name="address_proof" accept="image/*"
required>
<button type="submit">Add Customer</button>
</form>
</body>
</html>
View_customer.php
<?php
$conn = new mysqli('localhost', 'root', 'root', 'php');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>View Customers</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<h2>Customer List</h2>
<table>
<thead>
<tr>
<th>Customer ID</th>
<th>Name</th>
<th>Address</th>
<th>Contact No</th>
<th>Date of Birth</th>
<th>Email</th>
<th>Address Proof</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()) { ?>
<tr>
<td><?= $row['customer_id'] ?></td>
<td><?= $row['name'] ?></td>
<td><?= $row['address'] ?></td>
<td><?= $row['contact_no'] ?></td>
<td><?= $row['dob'] ?></td>
<td><?= $row['email'] ?></td>
<td><img src="uploads/address_proofs/<?=
$row['address_proof'] ?>" width="50" alt="address proof"></td>
<td><a href="delete_customer.php?id=<?= $row['customer_id']
?>" onclick="return confirm('Are you sure?')">Delete</a></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
Delete_customer.php
<?php
$conn = new mysqli('localhost', 'root', 'root', 'php');
if (isset($_GET['id'])) {
$customer_id = $_GET['id'];
$sql = "DELETE FROM customers WHERE customer_id=$customer_id";
search_customer.php
<?php
$conn = new mysqli('localhost', 'root', 'root', 'php ');
$search_result = null;
if (isset($_POST['search'])) {
$contact_no = $_POST['contact_no'];
$result = $conn->query("SELECT * FROM customers WHERE
contact_no = '$contact_no'");
$search_result = $result->fetch_assoc();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Search Customer</title>
<style>
input {
padding: 10px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h2>Search Customer by Contact No</h2>
<form method="POST">
<input type="text" name="contact_no" placeholder="Enter Contact
No" required>
<button type="submit" name="search">Search</button>
</form>
<?php
// Connect to the database
$conn = mysqli_connect("localhost", "root", "root");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
<?php
// Connect to the database
$conn = mysqli_connect("localhost", "root", "root");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Employee Management System</title>
</head>
<body>
<h2>Employee Management System</h2>
<nav>
<ul>
<li><a href="insert_emp.php">Insert Employee</a></li>
<li><a href="search_emp.php">Search Employee by
Department</a></li>
<li><a href="view_all_emp.php">View All Employees</a></li>
</ul>
</nav>
</body>
</html>
<?php
$conn = new mysqli("localhost", "root", "root", "php");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST['add_emp'])) {
$name = $conn->real_escape_string($_POST['name']);
$contactno = $conn->real_escape_string($_POST['contactno']);
$dept_id = (int)$_POST['dept_id'];
$empphoto = $_FILES['empphoto']['name'];
$empresume = $_FILES['empresume']['name'];
if (move_uploaded_file($_FILES['empphoto']['tmp_name'],
$photo_target) &&
move_uploaded_file($_FILES['empresume']['tmp_name'],
$resume_target)) {
$sql = "INSERT INTO Emp (name, contactno, dept_id, empphoto,
empresume)
VALUES ('$name', '$contactno', '$dept_id', '$empphoto',
'$empresume')";
if ($conn->query($sql) === TRUE) {
echo "Employee added successfully.";
} else {
echo "Error: " . $conn->error;
}
} else {
echo "Failed to upload files.";
}
}
// Fetch departments
$dept_query = "SELECT * FROM Dept";
$departments = $conn->query($dept_query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Insert Employee</title>
</head>
<body>
<h2>Insert Employee</h2>
<form action="insert_emp.php" method="POST"
enctype="multipart/form-data">
<label>Name:</label>
<input type="text" name="name" required><br>
<label>Contact No:</label>
<input type="text" name="contactno" required><br>
<label>Department:</label>
<select name="dept_id" required>
<?php while ($row = $departments->fetch_assoc()): ?>
<option value="<?= $row['dept_id'] ?>"><?= $row['dname']
?></option>
<?php endwhile; ?>
</select><br>
<label>Photo:</label>
<input type="file" name="empphoto" required><br>
<label>Resume:</label>
<input type="file" name="empresume" required><br>
<input type="submit" name="add_emp" value="Add Employee">
</form>
<a href="index.php">Back to Home</a>
</body>
</html>
<?php
$conn = new mysqli("localhost", "root", "root", "php");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch employees
$sql = "SELECT Emp.*, Dept.dname FROM Emp LEFT JOIN Dept ON
Emp.dept_id = Dept.dept_id";
$employees = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>All Employees</title>
</head>
<body>
<h2>All Employees</h2>
<table border="1">
<tr>
<th>Employee ID</th>
<th>Name</th>
<th>Contact No</th>
<th>Department</th>
<th>Photo</th>
<th>Resume</th>
<th>Actions</th>
</tr>
<?php while ($row = $employees->fetch_assoc()): ?>
<tr>
<td><?= $row['empid'] ?></td>
<td><?= $row['name'] ?></td>
<td><?= $row['contactno'] ?></td>
<td><?= $row['dname'] ?></td>
<td><img src="uploads/<?= $row['empphoto'] ?>"
width="50"></td>
<td><a href="uploads/<?= $row['empresume'] ?>"
target="_blank">View</a></td>
<td>
<a href="edit_emp.php?empid=<?= $row['empid']
?>">Edit</a> |
<a href="delete_emp.php?empid=<?= $row['empid'] ?>"
onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</table>
<a href="index.php">Back to Home</a>
</body>
</html>
<?php
$conn = new mysqli("localhost", "root", "root", "php");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST['search_dept'])) {
$dept_id = (int)$_POST['dept_id'];
$sql = "SELECT Emp.*, Dept.dname FROM Emp LEFT JOIN Dept ON
Emp.dept_id = Dept.dept_id WHERE Emp.dept_id = '$dept_id'";
$result = $conn->query($sql);
}
// Fetch departments
$dept_query = "SELECT * FROM Dept";
$departments = $conn->query($dept_query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Search Employee by Department</title>
</head>
<body>
<h2>Search Employee by Department</h2>
<form action="search_emp.php" method="POST">
<label>Department:</label>
<select name="dept_id" required>
<?php while ($row = $departments->fetch_assoc()): ?>
<option value="<?= $row['dept_id'] ?>"><?= $row['dname']
?></option>
<?php endwhile; ?>
</select>
<input type="submit" name="search_dept" value="Search">
</form>
<?php
// Create connection
$con = mysqli_connect("localhost", "root", "", "");
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_error());
} else {
echo "Connection successful<br>";
}
// Create database
if (mysqli_query($con, "CREATE DATABASE academic_institute")) {
echo "Database created successfully<br>";
} else {
echo "Error creating database: " . mysqli_error($con);
}
// Close connection
mysqli_close($con);
?>
• Output:
Connection successful
Database created successfully
• Academic Institute:
<?php
// Database connection
$conn = new mysqli('localhost', 'root','','academic_institute');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create tables if they do not exist
$create_course_table = "CREATE TABLE IF NOT EXISTS BCourse (
Course_id INT AUTO_INCREMENT PRIMARY KEY,
Course_type VARCHAR(100) NOT NULL,
Fees DECIMAL(10, 2) NOT NULL
)";
$conn->query($create_course_table);
$create_student_table = "CREATE TABLE IF NOT EXISTS Student (
Stud_id INT AUTO_INCREMENT PRIMARY KEY,
Stud_name VARCHAR(100) NOT NULL,
Course_id INT NOT NULL,
Contact_no VARCHAR(15) NOT NULL UNIQUE,
Address VARCHAR(255),
photo VARCHAR(255),
FOREIGN KEY (Course_id) REFERENCES BCourse(Course_id)
)";
$conn->query($create_student_table);
// Sample Courses (uncomment to add sample data)
$sample_courses = [
["IT", 1000],
["Management", 1200],
["Commerce", 800]
];
foreach ($sample_courses as $course) {
$conn->query("INSERT IGNORE INTO BCourse (Course_type, Fees)
VALUES ('$course[0]', $course[1])");
}
// Handle adding a new student
if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
isset($_POST['add_student'])) {
$name = $_POST['stud_name'];
$contact_no = $_POST['contact_no'];
$address = $_POST['address'];
$course_id = $_POST['course_id'];
// File upload
$photo = $_FILES['photo']['name'];
move_uploaded_file($_FILES['photo']['tmp_name'], 'uploads/' .
$photo);
$stmt = $conn->prepare("INSERT INTO Student (Stud_name, Course_id,
Contact_no, Address, photo) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sisss", $name, $course_id, $contact_no,
$address, $photo);
if ($stmt->execute()) {
echo "<p class='success'>Student added successfully!</p>";
} else {
echo "<p class='error'>Error: " . $stmt->error . "</p>";
}
$stmt->close();
}
// Handle updating a student
if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
isset($_POST['update_student'])) {
$stud_id = $_POST['stud_id'];
$name = $_POST['stud_name'];
$contact_no = $_POST['contact_no'];
$address = $_POST['address'];
$course_id = $_POST['course_id'];
$stmt = $conn->prepare("UPDATE Student SET Stud_name=?,
Course_id=?, Contact_no=?, Address=? WHERE Stud_id=?");
$stmt->bind_param("sissi", $name, $course_id, $contact_no,
$address, $stud_id);
if ($stmt->execute()) {
echo "<p class='success'>Student updated successfully!</p>";
} else {
echo "<p class='error'>Error: " . $stmt->error . "</p>";
}
$stmt->close();
}
// Handle deleting a student
if (isset($_GET['delete_id'])) {
$id = $_GET['delete_id'];
$conn->query("DELETE FROM Student WHERE Stud_id=$id");
}
// Handle searching students
$search_result = null;
if (isset($_POST['search_student'])) {
$course_id = $_POST['course_id'];
$search_result = $conn->query("SELECT * FROM Student WHERE
Course_id='$course_id'");
}
// Fetch all courses for dropdown
$courses = $conn->query("SELECT * FROM BCourse");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Academic Institute Management</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background-color:
#f4f4f4; }
.container { max-width: 800px; margin: auto; background: #fff;
padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0,
0.1); }
h2 { border-bottom: 2px solid #007BFF; padding-bottom: 10px;
color: #007BFF; }
label { display: block; margin: 10px 0 5px; }
input[type="text"], input[type="file"], select {
width: calc(100% - 20px);
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
padding: 10px 15px;
background-color: #007BFF;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover { background-color: #0056b3; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
table, th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #007BFF; color: #fff; }
.success { color: green; }
.error { color: red; }
.delete-link { color: red; text-decoration: none; }
.delete-link:hover { text-decoration: underline; }
</style>
</head>
<body>
<div class="container">
<h2>Add New Student</h2>
<form action="" method="post" enctype="multipart/form-data">
<label>Name:</label>
<input type="text" name="stud_name" required
placeholder="Enter Student Name">
<label>Contact No:</label>
<input type="text" name="contact_no" required
placeholder="Enter Contact No">
<label>Address:</label>
<input type="text" name="address" required placeholder="Enter
Address">
<label>Course:</label>
<select name="course_id" required>
<option value="">Select Course</option>
<?php while ($row = $courses->fetch_assoc()): ?>
<option value="<?php echo $row['Course_id']; ?>"><?php echo
$row['Course_type']; ?></option>
<?php endwhile; ?>
</select>
<label>Photo:</label>
<input type="file" name="photo" accept="image/*" required>
<button type="submit" name="add_student">Add Student</button>
</form>
<h2>Search Students by Course</h2>
<form action="" method="post">
<label>Course:</label>
<select name="course_id" required>
<option value="">Select Course</option>
<?php
$courses->data_seek(0); // Reset pointer to the beginning
while ($row = $courses->fetch_assoc()): ?>
<option value="<?php echo $row['Course_id']; ?>"><?php
echo $row['Course_type']; ?></option>
<?php endwhile; ?>
</select>
<button type="submit" name="search_student">Search</button>
</form>
<?php if ($search_result): ?>
<h3>Search Results</h3>
<table>
<tr>
<th>Student ID</th>
<th>Name</th>
<th>Contact No</th>
<th>Address</th>
<th>Course ID</th>
<th>Photo</th>
<th>Actions</th>
</tr>
<?php while ($row = $search_result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['Stud_id']; ?></td>
<td><?php echo $row['Stud_name']; ?></td>
<td><?php echo $row['Contact_no']; ?></td>
<td><?php echo $row['Address']; ?></td>
<td><?php echo $row['Course_id']; ?></td>
<td><img src="uploads/<?php echo $row['photo']; ?>"
width="50" alt="Student Photo"></td>
<td>
<a class="delete-link" href="?delete_id=<?php echo
$row['Stud_id']; ?>" onclick="return confirm('Are you sure you want to
delete this student?');">Delete</a>
<a href="#" onclick="editStudent(<?php echo
$row['Stud_id']; ?>, '<?php echo $row['Stud_name']; ?>', '<?php echo
$row['Contact_no']; ?>', '<?php echo $row['Address']; ?>', <?php echo
$row['Course_id']; ?>)">Edit</a>
</td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>
<h2>All Students</h2>
<table>
<tr>
<th>Student ID</th>
<th>Name</th>
<th>Contact No</th>
<th>Address</th>
<th>Course ID</th>
<th>Photo</th>
<th>Actions</th>
</tr>
<?php $all_students = $conn->query("SELECT * FROM Student");
?>
<?php while ($row = $all_students->fetch_assoc()): ?>
<tr>
<td><?php echo $row['Stud_id']; ?></td>
<td><?php echo $row['Stud_name']; ?></td>
<td><?php echo $row['Contact_no']; ?></td>
<td><?php echo $row['Address']; ?></td>
<td><?php echo $row['Course_id']; ?></td>
<td><img src="uploads/<?php echo $row['photo']; ?>"
width="50" alt="Student Photo"></td>
<td>
<a class="delete-link" href="?delete_id=<?php echo
$row['Stud_id']; ?>" onclick="return confirm('Are you sure you want to
delete this student?');">Delete</a>
<a href="#" onclick="editStudent(<?php echo $row['Stud_id'];
?>, '<?php echo $row['Stud_name']; ?>', '<?php echo
$row['Contact_no']; ?>', '<?php echo $row['Address']; ?>', <?php echo
$row['Course_id']; ?>)">Edit</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
<script>
function editStudent(stud_id, name, contact_no, address,
course_id) {
const courses = <?php
$courses->data_seek(0);
echo json_encode($courses->fetch_all(MYSQLI_ASSOC));
?>;
let options = '<option value="">Select Course</option>';
courses.forEach(course => {options += `<option
value="${course.Course_id}" ${course_id == course.Course_id ?
'selected' : ''}>${course.Course_type}</option>`;
});
document.querySelector('.container').innerHTML += `
<h2>Update Student</h2>
<form action="" method="post" enctype="multipart/form-
data">
<input type="hidden" name="stud_id" value="${stud_id}">
<label>Name:</label>
<input type="text" name="stud_name" value="${name}"
required>
<label>Contact No:</label>
<input type="text" name="contact_no"
value="${contact_no}" required> <label>Address:</label>
<input type="text" name="address" value="${address}"
required>
<label>Course:</label>
<select name="course_id" required>${options}</select>
<button type="submit" name="update_student">Update
Student</button>
</form>’; }
</script>
</body>
</html>
<?php $conn->close(); ?>
• Search,update and delete:
• Database:
• ===========================================================
5.Create Php Web Pages for Student Registration form with following
fields: Student Name, Enrollment Number, Department, Year, Sem,
Mobile no., email id, address, username, password, confirm password.
Details should be edit, Delete and View with appropriate validations.
Also apply proper design accordingly. Note: Create tables as per required
and Provide Validations as wherever required, also make the use of
Sessions, Cookies and jQuery.
<?php
// Connect to the database
$conn = mysqli_connect("localhost", "root", "root");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
<?php
$conn = new mysqli('localhost', 'root', 'root', 'php');
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Get form data
$enrollment_number = $_POST['enrollment_number'];
$student_name = $_POST['student_name'];
$department = $_POST['department'];
$year = $_POST['year'];
$semester = $_POST['semester'];
$mobile_no = $_POST['mobile_no'];
$email_id = $_POST['email_id'];
$address = $_POST['address'];
$username = $_POST['username'];
$password = password_hash($_POST['password'],
PASSWORD_BCRYPT); // Hashing the password
if ($check_result->num_rows > 0) {
echo "Username or Enrollment number already exists.";
} else {
// Insert student into database
$sql = "INSERT INTO Student (enrollment_number, student_name,
department, year, semester, mobile_no, email_id, address, username,
password)
VALUES ('$enrollment_number', '$student_name',
'$department', '$year', '$semester', '$mobile_no', '$email_id',
'$address', '$username', '$password')";
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Student Registration</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('#registrationForm').on('submit', function(e) {
var password = $('#password').val();
var confirmPassword = $('#confirm_password').val();
if (password !== confirmPassword) {
alert("Passwords do not match!");
e.preventDefault();
}
});
});
</script>
</head>
<body>
<h2>Student Registration</h2>
<form id="registrationForm" method="POST">
<input type="text" name="enrollment_number"
placeholder="Enrollment Number" required><br>
<input type="text" name="student_name" placeholder="Student
Name" required><br>
<input type="text" name="department" placeholder="Department"
required><br>
<input type="number" name="year" placeholder="Year"
required><br>
<input type="text" name="semester" placeholder="Semester"
required><br>
<input type="text" name="mobile_no" placeholder="Mobile No"
required><br>
<input type="email" name="email_id" placeholder="Email ID"
required><br>
<textarea name="address" placeholder="Address"
required></textarea><br>
<input type="text" name="username" placeholder="Username"
required><br>
<input type="password" id="password" name="password"
placeholder="Password" required><br>
<input type="password" id="confirm_password"
placeholder="Confirm Password" required><br>
<button type="submit">Register</button>
</form>
</body>
</html>
<?php
$conn = new mysqli('localhost', 'root', 'root', 'php');
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM Student WHERE username='$username'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
// Set session
$_SESSION['username'] = $user['username'];
header("Location: dashboard.php");
} else {
echo "Invalid password.";
}
} else {
echo "Username does not exist.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<form method="POST">
<input type="text" name="username" placeholder="Username"
required><br>
<input type="password" name="password" placeholder="Password"
required><br>
<label>
<input type="checkbox" name="remember_me"> Remember Me
</label><br>
<button type="submit">Login</button>
</form>
</body>
</html>
<?php
session_start();
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Dashboard</title>
</head>
<body>
<h2>Welcome, <?= $_SESSION['username'] ?></h2>
<a href="edit_student.php">Edit Details</a> |
<a href="delete_student.php">Delete Account</a> |
<a href="view_student.php">View Details</a> |
<a href="logout.php">Logout</a>
</body>
</html>
<?php
session_start();
$conn = new mysqli('localhost', 'root', 'root', 'php');
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit;
}
$username = $_SESSION['username'];
$sql = "SELECT * FROM Student WHERE username='$username'";
$result = $conn->query($sql);
$student = $result->fetch_assoc();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$student_name = $_POST['student_name'];
$department = $_POST['department'];
$year = $_POST['year'];
$semester = $_POST['semester'];
$mobile_no = $_POST['mobile_no'];
$email_id = $_POST['email_id'];
$address = $_POST['address'];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Edit Student Details</title>
</head>
<body>
<h2>Edit Student Details</h2>
<form method="POST">
<input type="text" name="student_name" value="<?=
$student['student_name'] ?>" required><br>
<input type="text" name="department" value="<?=
$student['department'] ?>" required><br>
<input type="number" name="year" value="<?= $student['year'] ?>"
required><br>
<input type="text" name="semester" value="<?=
$student['semester'] ?>" required><br>
<input type="text" name="semester" value="<?=
$student['semester'] ?>" required><br>
<input type="text" name="mobile_no" value="<?=
$student['mobile_no'] ?>" required><br>
<input type="email" name="email_id" value="<?=
$student['email_id'] ?>" required><br>
<textarea name="address" required><?= $student['address']
?></textarea><br>
<button type="submit">Update</button>
</form>
</body>
</html>
<?php
session_start();
$conn = new mysqli('localhost', 'root', 'root', 'php');
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit;
}
$username = $_SESSION['username'];
<?php
session_start();
$conn = new mysqli('localhost', 'root', 'root', 'php');
if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit;
}
$username = $_SESSION['username'];
$sql = "SELECT * FROM Student WHERE username='$username'";
$result = $conn->query($sql);
$student = $result->fetch_assoc();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>View Student Details</title>
</head>
<body>
<h2>Student Details</h2>
<p><strong>Enrollment Number:</strong> <?=
$student['enrollment_number'] ?></p>
<p><strong>Student Name:</strong> <?= $student['student_name']
?></p>
<p><strong>Department:</strong> <?= $student['department']
?></p>
<p><strong>Year:</strong> <?= $student['year'] ?></p>
<p><strong>Semester:</strong> <?= $student['semester'] ?></p>
<p><strong>Mobile No:</strong> <?= $student['mobile_no'] ?></p>
<p><strong>Email ID:</strong> <?= $student['email_id'] ?></p>
<p><strong>Address:</strong> <?= $student['address'] ?></p>
</body>
</html>
<?php
session_start();
session_destroy();
header('Location: login.php');
exit;
?>