[go: up one dir, main page]

0% found this document useful (0 votes)
5 views15 pages

Fsd-Assignment:: Student App

Uploaded by

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

Fsd-Assignment:: Student App

Uploaded by

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

FSD-

Assignment:
2211CS020420

Pranav Santosh Rao

1. Student App:

Index.html:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="css/style.css">

<title>Student Management System</title>

</head>

<body>

<div class="index-container">

<h1>Student Management System</h1>

<div class="button-container">

<a href="insert_student.html" class="btn">Insert Data</a>

<a href="php/view_students.php" class="btn">View Data</a>

</div>

</div>

</body>

</html>

Insert.php:

<?php

// Database connection

$servername = "localhost";

$username = "root";

$password = "";
$dbname = "student_management";

// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$student_name = $_POST['student_name'];

$roll_number = $_POST['roll_number'];

$section = $_POST['section'];

$dob = $_POST['dob'];

$address = $_POST['address'];

$gender = $_POST['gender'];

$area_of_interest = implode(', ', $_POST['area_of_interest']); // Multiple select

// File upload handling

$resume = $_FILES['resume']['name'];

$target_dir = "../uploads/";

$target_file = $target_dir . basename($resume);

$file_type = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));

// Validate file type and

size if ($file_type != "pdf") {

echo "Only PDF files are

allowed."; exit;

} elseif ($_FILES["resume"]["size"] > 200000) { // Max 200KB

echo "File size exceeds 200KB.";


exit;

// Move the file to the uploads directory

if (move_uploaded_file($_FILES["resume"]["tmp_name"], $target_file)) {

// Insert data into the database

$sql = "INSERT INTO students (student_name, roll_number, section, dob, address, gender,
area_of_interest, resume_path)

VALUES ('$student_name', '$roll_number', '$section', '$dob', '$address', '$gender',


'$area_of_interest', '$target_file')";

if ($conn->query($sql) === TRUE) {

echo "<script>alert('Student data inserted successfully.');


window.location.href='../index.html';</script>";

} else {

echo "Error: " . $sql . "<br>" . $conn->error;

} else {

echo "Error uploading the file.";

$conn->close();

?>

View.php:

<?php

// Database connection

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "student_management";
$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

$search = isset($_GET['search']) ? $_GET['search'] : '';

$sql = "SELECT * FROM students WHERE student_name LIKE '%$search%' OR roll_number LIKE '%
$search%'";

$result = $conn->query($sql);

?>

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="../css/style.css">

<title>View Students</title>

</head>

<body>

<h1>Student Records</h1>

<form method="GET" action="">

<input type="text" name="search" placeholder="Search by name or roll number" value="<?php


echo $search; ?>">

<input type="submit" value="Search">

</form>

<table>

<tr>
<th>Name</th>

<th>Roll Number</th>

<th>Section</th>

<th>DOB</th>

<th>Address</th>

<th>Gender</th>

<th>Interests</th>

<th>Resume</th>

</tr>

<?php

if ($result->num_rows > 0) {

while($row = $result->fetch_assoc())

{ echo "<tr>

<td>{$row['student_name']}</td>

<td>{$row['roll_number']}</td>

<td>{$row['section']}</td>

<td>{$row['dob']}</td>

<td>{$row['address']}</td>

<td>{$row['gender']}</td>

<td>{$row['area_of_interest']}</td>

<td><a href='{$row['resume_path']}'>Download</a></td>

</tr>";

} else {

echo "<tr><td colspan='8'>No records found</td></tr>";

$conn->close();

?>

</table>

</body>

</html>
Output:
2. Employee:

Index.html:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Employee Form</title>

</head>

<body>

<form id="employeeForm">

<label for="country">Country:</label>

<select id="country" name="country" onchange="populateState()">

<option value="">Select Country</option>

<option value="USA">USA</option>

<option value="India">India</option>

</select>

<label for="state">State:</label>

<select id="state" name="state" onchange="populateCity()">


<option value="">Select State</option>

</select>

<label for="city">City:</label>

<select id="city" name="city">

<option value="">Select City</option>

</select>

<!-- Other form fields like Employee Name, ID, etc. go here -->

<input type="submit" value="Submit">

<button type="button" onclick="window.location.href='homepage.html'">Cancel</button>

</form>

<!-- JavaScript goes here -->

<script>

const stateCityMapping =

{ "USA": {

"Alabama": ["Birmingham", "Montgomery", "Huntsville"],

"Alaska": ["Anchorage", "Fairbanks", "Juneau"],

// ... all other USA states and cities

},

"India": {

"Andhra Pradesh": ["Visakhapatnam", "Vijayawada", "Guntur"],

"Karnataka": ["Bangalore", "Mysore", "Mangalore"],

// ... all other Indian states and cities

};

function populateState() {

const country = document.getElementById("country").value;


const state = document.getElementById("state");

const city = document.getElementById("city");

state.innerHTML = `<option value="">Select State</option>`;

city.innerHTML = `<option value="">Select City</option>`; // Reset city dropdown

if (stateCityMapping[country]) {

for (let st in stateCityMapping[country]) {

const option = document.createElement("option");

option.value = st;

option.textContent = st;

state.appendChild(option);

function populateCity() {

const country = document.getElementById("country").value;

const state = document.getElementById("state").value;

const city = document.getElementById("city");

city.innerHTML = `<option value="">Select City</option>`;

if (stateCityMapping[country] && stateCityMapping[country][state]) {

const cities = stateCityMapping[country][state];

cities.forEach(function (cityName) {

const option = document.createElement("option");

option.value = cityName;

option.textContent = cityName;

city.appendChild(option);

});
}

</script>

</body>

</html>

Process.php:

<?php

// Connect to Database

$servername = "localhost";

$username = "root"; // Default XAMPP username

$password = ""; // Default XAMPP password

$dbname = "employee_db"; // Your database name

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

// Check if form is submitted

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$name = $_POST['employeeName'];

$id = $_POST['employeeId'];

$doj = $_POST['doj'];

$gender = $_POST['gender'];

$country = $_POST['country'];

$state = $_POST['state'];

$city = $_POST['city'];

// File Upload Logic


$photo = $_FILES['employeePhoto'];

$photoName = $_FILES['employeePhoto']['name'];

$photoSize = $_FILES['employeePhoto']['size'];

$photoTmpName = $_FILES['employeePhoto']['tmp_name'];

$photoExt = strtolower(pathinfo($photoName, PATHINFO_EXTENSION));

if ($photoExt != "png" || $photoSize < 20480 || $photoSize > 51200) {

die("File must be a PNG and between 20KB and 50KB.");

// Save File

$uploadDir = "uploads/";

$uploadFilePath = $uploadDir . basename($photoName);

move_uploaded_file($photoTmpName, $uploadFilePath);

// Insert Data into Database

$sql = "INSERT INTO employees (name, employee_id, date_of_joining, gender, photo, country,
state, city)

VALUES ('$name', '$id', '$doj', '$gender', '$photoName', '$country', '$state', '$city')";

if ($conn->query($sql) === TRUE) {

echo "Employee added successfully!";

} else {

echo "Error: " . $sql . "<br>" . $conn->error;

$conn->close();

?>
Output:

You might also like