Web Project
Web Project
*{
box-sizing: border-box;
/* font-family: "Roboto", sans-serif; */
font-family: "Montserrat", sans-serif;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
login.css
@import url(./header.css); .container > input::placeholder,
.container > input {
body { padding: 10px 5px;
height: 100vh; font-size: 16px;
display: flex; }
justify-content: center; .container > input:focus {
align-items: center; outline: none;
background: rgb(154, 208, 194); }
background: linear-gradient(
180deg, #redirect,
rgba(154, 208, 194, 1) 58%, #login {
rgba(236, 244, 214, 1) 100% width: 100%;
); background-color: #265073;
} color: white;
outline: none;
.outerContainerLogin { border: none;
display: flex; border-radius: 20px;
justify-content: center; padding: 8px 5px;
align-items: stretch; }
width: 40%;
border-radius: 10px; #sessionDiv {
box-shadow: -4px 6px 10px 1px rgba(0, 0, 0, margin: 20px 0px;
0.42); }
-webkit-box-shadow: -4px 6px 10px 1px rgba(0,
0, 0, 0.42); button {
-moz-box-shadow: -4px 6px 10px 1px rgba(0, 0, font-size: 16px;
0, 0.42); }
}
a{
.sideImageContainer { text-decoration: none;
width: 55%; color: white;
background-image: font-size: 16px;
url(../images/loginSide1.jpg); }
background-size: cover;
border-radius: 10px 0px 0px 10px; .externalDiv,
} #buttonContainer {
.formContainer { padding: 0px 10px;
width: 45%; }
button:hover {
padding: 30px 50px; transform: scale(1.01);
flex: 1; cursor: pointer;
border-radius: 0px 10px 10px 0px; }
background-color: #e1e8ea;
} .errorClass {
border: 3px solid #ff8888 !important;
#header { border-radius: 0.5em;
margin-bottom: 40px; }
color: #265073;
} #failedLogin,
#connectionFailure {
h1 { padding: 10px;
font-weight: 500px; border-radius: 10px;
font-size: 30px; position: absolute;
text-align: center; right: 10px;
} top: 10px;
transform: translateX(1000px);
.container, transition: transform 1000ms;
.externalDiv { background-color: #ff8888;
width: 100%; color: white;
margin-bottom: 10px; font-weight: 500;
} }
.errorClass {
border: 3px solid #ff8888 !important;
border-radius: 0.5em;
}
tableLayout.css
@import url(./header.css); Td,th {
padding: 10px;
body { text-align: center;
height: 100vh; }
display: flex;
justify-content: center; th {
align-items: center; background-color: #265073;
background: linear-gradient( color: white;
180deg, }
rgba(154, 208, 194, 1) 58%,
rgba(236, 244, 214, 1) 100% .oddRow {
); background-color: rgb(211, 211, 211);
} }
.outerLayoutContainer {
display: flex; .evenRow {
flex-direction: column; background-color: #fffef1;
justify-content: center; }
align-items: center;
} .heading {
margin-bottom: 40px;
table, font-size: 34px;
td, font-weight: 500;
th { color: #265073;
border: 1px solid white; text-align: center;
border-collapse: collapse; }
}
handleFormSubmission.js
document.getElementById("studentForm").addEvent let phone =
Listener("submit", function (e) { document.getElementById("phone");
e.preventDefault(); let email =
if (validateForm()) { document.getElementById("email");
submitForm(); let isChecked =
} document.getElementById("agree");
});
let errors = {
function submitForm() { firstName: false,
let myForm = lastName: false,
document.getElementById("studentForm"); email: false,
let myFormData = new FormData(myForm); phone: false,
fetch("../php/dataSubmission.php", { street: false,
method: "POST", state: false,
body: myFormData, district: false,
}) city: false,
.then((response) => response.json()) course: false,
.then((data) => { agree: false,
if (data.success) { university: false,
handleSlide("successSubmit"); college: false,
} else { rollNo: false,
handleSlide("submitFailure"); regNo: false,
} };
})
.catch((error) => { validateStringAndAddError(errors,
firstName.value, "firstName");
document.getElementById("connectionFailure").inne validateStringAndAddError(errors,
rHTML = error; lastName.value, "lastName");
handleSlide("connectionFailure"); validateStringAndAddError(errors,
}); course.value, "course");
} validateStringAndAddError(errors,
university.value, "university");
function isString(value) { validateStringAndAddError(errors,
return value.match(/^[a-zA-Z]+( )*[a-zA-Z]+$/); state.value, "state");
} validateStringAndAddError(errors,
district.value, "district");
function isPhoneNumber(value) { validateStringAndAddError(errors, city.value,
return value.length == 10 && value.match(/^9[0- "city");
9]+$/);
} if (!rollNo.value || !isNumber(rollNo.value)) {
errors["rollNo"] = true;
function isNumber(value) { }
return value.match(/^[0-9]+$/);
} if (!regNo.value || !isRegNo(regNo.value)) {
errors["regNo"] = true;
function isRegNo(value) { }
return value.match(/^([0-9]+-)+[0-9]+$/);
} if (street.value && !
isAlphaNumeric(street.value)) {
function isAlphaNumeric(value) { errors["street"] = true;
return value.match(/^[0-9a-zA-Z]+[0-9a-zA-Z ]*[0- }
9a-zA-Z]+$/);
} if (!college.value && !
isAlphaNumeric(college.value)) {
function isEmail(value) { errors["college"] = true;
let atpos = value.indexOf("@"); }
let dotpos = value.indexOf(".");
if (!phone.value || !
return !(atpos < 1) && !(dotpos - atpos < 2); isPhoneNumber(phone.value)) {
} errors["phone"] = true;
}
function validateStringAndAddError(errors, variable,
dataName) { if (!email.value || !isEmail(email.value)) {
if (!variable || !isString(variable)) { errors["email"] = true;
errors[dataName] = true; }
}
} if (!isChecked.checked) {
errors["agree"] = true;
function handleSlide(val) { }
let ele = document.getElementById(val);
ele.style.transform = "translateX(0)"; let valid = true;
setTimeout(function () { for (key in errors) {
ele.style.transform = "translateX(1000px)"; if (errors[key]) {
}, 3000); valid = false;
} if (key == "agree") {
handleSlide("notAgreed");
function validateForm() { } else {
// gathering the data
let firstName = document.getElementById(key).classList.add("
document.getElementById("firstName"); errorClass");
let lastName = handleSlide("submitFailure");
document.getElementById("lastName"); }
let course = document.getElementById("course"); } else {
let university =
document.getElementById("university"); document.getElementById(key).classList.remo
let college = document.getElementById("college"); ve("errorClass");
let rollNo = document.getElementById("rollNo"); }
let regNo = document.getElementById("regNo"); }
let state = document.getElementById("state"); return valid;
let district = document.getElementById("district"); }
let city = document.getElementById("city");
let street = document.getElementById("street");
loginHandle.js
document.getElementById("loginForm").addEventLi
stener("submit", function (e) { function handleSlide(val) {
e.preventDefault(); let ele = document.getElementById(val);
if (validateData()) { ele.style.transform = "translateX(0)";
submitForm(); setTimeout(function () {
} ele.style.transform = "translateX(1000px)";
}); }, 3000);
}
function handleFailure(key) {
let errorMsg = function validateData() {
document.getElementById("failedLogin"); let username =
document.getElementById("username");
document.getElementById(key).classList.add("error let password =
Class"); document.getElementById("password");
errorMsg.style.transform = "translateX(0)";
setTimeout(function () { let errors = {
errorMsg.style.transform = "translateX(1000px)"; username: false,
}, 3000); password: false,
} };
function isUsername(username) {
return username.match(/^[a-zA-Z]+/);
}
function isPassword(password) {
// atleast one uppercase one lowercase one digit
and 8 characters long
return password.match(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])
[A-Za-z\d@$!%*?&]{8,}$/
);
}
provienceAndDistrict.js
var provinces = { Lumbini: [
Koshi: [ "Arghakhanchi",
"Bhojpur", "Banke",
"Dhankuta", "Bardiya",
"Ilam", "Dang",
"Jhapa", "Eastern Rukum",
"Khotang", "Gulmi",
"Morang", "Kapilvastu",
"Okhaldhunga", "Parasi",
"Panchthar", "Palpa",
"Sankhuwasabha", "Rupandehi",
"Solukhumbu", "Rolpa",
"Sunsari", "Rukum",
"Taplejung", ],
"Terhathum",
"Udayapur", Karnali: [
], "Dailekh",
Madhesh: [ "Dolpa",
"Bara", "Humla",
"Dhanusa", "Jajarkot",
"Mahottari", "Jumla",
"Parsa", "Kalikot",
"Rautahat", "Mugu",
"Saptari", "Salyan",
"Sarlahi", "Surkhet",
"Siraha", "Western Rukum",
], ],
Bagmati: [ Sudurpashchim: [
"Bhaktapur", "Achham",
"Chitwan", "Baitadi",
"Dhading", "Bajhang",
"Dolakha", "Bajura",
"Kathmandu", "Dadeldhura",
"Kavrepalanchok", "Darchula",
"Lalitpur", "Doti",
"Makwanpur", "Kailali",
"Nuwakot", "Kanchanpur",
"Ramechhap", ],
"Rasuwa", };
"Sindhuli",
"Sindhupalchok", function addDistricts() {
], let state =
Gandaki: [ document.getElementById("state").value;
"Baglung", let district =
"Gorkha", document.getElementById("district");
"Kaski",
"Lamjung", district.innerHTML =
"Manang", "<option value='' disabled selected>Select Your
"Mustang", District</option>";
"Myagdi",
"Nawalpur", if (state) {
"Parbat", provinces[state].forEach((element) => {
"Syangja", let option =
"Tanahun", document.createElement("option");
], option.value = element;
option.text = element;
district.add(option);
});
}
}
dataLayout.php
<?php <th>Registration No</th>
const DB_HOST = "localhost"; <th>State</th>
const DB_USER = "srijan"; <th>District</th>
const DB_PASS = "123456"; <th>City</th>
const DB_NAME = "semester_project"; <th>Phone</th>
<th>Email</th>
$conn = new mysqli(DB_HOST, DB_USER, </tr>
DB_PASS, DB_NAME); <?php $count = 0 ?>
if ($conn->connect_error) { <?php foreach ($data as $person) : ?>
die("Connection Failed" . $conn- <tr class="<?php echo ($count++ % 2 == 0) ?
>connect_error); "evenRow" : "oddRow"
} ?>">
<td><?php echo $person["ID"] ?></td>
$sql = "SELECT * FROM student_form"; <td><?php echo $person["First_Name"] ?
$result = mysqli_query($conn, $sql); ></td>
$data = mysqli_fetch_all($result, <td><?php echo $person["Last_Name"] ?
MYSQLI_ASSOC); ></td>
<td><?php echo $person["Course"] ?></td>
?> <td><?php echo $person["University"]
<!DOCTYPE html> ?></td>
<html lang="en"> <td><?php echo $person["College"] ?></td>
<td><?php echo $person["Roll_No"]
<head> ?></td>
<meta charset="UTF-8" /> <td><?php echo $person["Reg_No"]
<meta name="viewport" ?></td>
content="width=device-width, initial- <td><?php echo $person["State"] ?></td>
scale=1.0" /> <td><?php echo $person["District"] ?></td>
<title>Data Layout</title> <td><?php echo $person["City"] ?></td>
<link rel="stylesheet" <td><?php echo $person["Phone"] ?></td>
href="../css/tableLayout.css"> <td><?php echo $person["Email"] ?></td>
</head> </tr>
<?php endforeach; ?>
<body> </table>
<div class="outerLayoutContainer"> </div>
<div class="heading">Student's Detail
Table</div> </body>
<table id="layoutTable">
<tr id="headingRow"> </html>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Course</th>
<th>Univerity</th>
<th>College</th>
<th>Roll No</th>
dataSubmission.php
<?php $college = handleStringValidation($college,
const DB_HOST = "localhost"; "college", $errors);
const DB_USER = "srijan"; $state = handleStringValidation($state, "state",
const DB_PASS = "123456"; $errors);
const DB_NAME = "semester_project"; $regNo = handleStringValidation($regNo,
"regNo", $errors);
$conn = new mysqli(DB_HOST, DB_USER, $district = handleStringValidation($district,
DB_PASS, DB_NAME); "district", $errors);
if ($conn->connect_error) { $city = handleStringValidation($city, "city",
die("Connection failed " . $connect->error); $errors);
} $street = handleStringValidation($street,
"street", $errors);
function handleStringValidation($value, $type, $phone = handleStringValidation($phone,
&$errors) "phone", $errors);
{
if (!$value) { if (!$rollNo) {
$errors[$type] = 'Invalid ' . $type . ' provided'; $errors['rollNo'] = "Invalid rollNo provided";
} else { } else {
return filter_var($value, $rollNo = filter_var($rollNo,
FILTER_SANITIZE_FULL_SPECIAL_CHARS); FILTER_VALIDATE_INT);
} }
}
if (!$email) {
if ($_SERVER["REQUEST_METHOD"] == "POST") { $errors["email"] = "Invalid email provided";
if (isset($_POST["firstName"])) { } else {
$firstName = $_POST["firstName"]; $email = filter_var($email,
$lastName = $_POST["lastName"]; FILTER_VALIDATE_EMAIL);
$course = $_POST["course"]; }
$university = $_POST["university"];
$college = $_POST["college"]; if (count($errors) == 0) {
$rollNo = $_POST["rollNo"]; $sql = "INSERT INTO student_form
$regNo = $_POST["regNo"]; (First_Name, Last_Name, Course, University,
$state = $_POST["state"]; College, Roll_No,Reg_No, State, District, City,
$district = $_POST["district"]; Street, Phone, Email) VALUES ('$firstName',
$city = $_POST["city"]; '$lastName', '$course', '$university', '$college',
$street = $_POST["street"]; '$rollNo', '$regNo', '$state', '$district', '$city',
$phone = $_POST["phone"]; '$street', '$phone', '$email')";
$email = $_POST["email"];
} if (mysqli_query($conn, $sql)) {
$response = [
$errors = []; "success" => true,
// sanitazation and validation "message" => "Successfully inserted
$firstName = data",
handleStringValidation($firstName, "firstName", ];
$errors); } else {
$lastName = $response = [
handleStringValidation($lastName, "lastName", "success" => false,
$errors); "message" => "Error inserting data",
$course = handleStringValidation($course, ];
"course", $errors); }
$university = } else {
handleStringValidation($university, "university", $response = [
$errors); "success" => false,
"message" => "Data not valid",
];
}
header('Content-Type: application/json');
echo json_encode($response);
}
login.php
<?php } else {
$response = [
session_start(); "success" => false,
if ($_SERVER["REQUEST_METHOD"] == "POST") { 'error' => "Incorrect Password",
$username = $_POST["username"]; ];
$password = $_POST["password"]; }
}
$result = isset($_SESSION[$username]) ||
$username == "admin" && $password == header('Content-Type: application/json');
"User@2024";
echo json_encode($response);
if ($result) { }
$remember = $_POST["doRemember"];
if ($remember && !
isset($_SESSION[$username])) {
$_SESSION["username"] = $username;
$_SESSION["password"] = $password;
}
$response = [
'success' => true,
'redirectURL' => "../php/dataLayout.php",
];
} else {
if ($username != 'admin') {
$response = [
"success" => false,
'error' => "Incorrect Username",
];