0% found this document useful (0 votes)
17 views21 pages

Web Project

The document outlines the file structure of a semester project. It includes folders for CSS, images, JS, and PHP files. It also includes two HTML files - an index file for login and a student form file to submit details. The files work together using JavaScript to handle form submissions and dynamically populate province/district dropdowns.
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)
17 views21 pages

Web Project

The document outlines the file structure of a semester project. It includes folders for CSS, images, JS, and PHP files. It also includes two HTML files - an index file for login and a student form file to submit details. The files work together using JavaScript to handle form submissions and dynamically populate province/district dropdowns.
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/ 21

Contents

No table of contents entries found.


My File Structure
Semester-project/
|-- css/
| |-- header.css
| |-- login.css
| |-- style.css
| |-- tableLayout.css
|
|-- images/
| |-- loginSlide1.jpeg
|
|-- js/
| |-- handleFormSubmit.js
| |-- loginHandle.js
| |-- provinceAndDistrict.js
|
|-- php/
| |-- dataLayout.php
| |-- dataSubmission.php
| |-- login.php
|
|-- public/
| |-- index.html
| |-- studentForm.html
index.html
<!DOCTYPE html> <button type="submit" name="login"
<html lang="en"> id="login">Login</button>
<head> </div>
<meta charset="UTF-8" /> </form>
<meta name="viewport" <div class="externalDiv"
content="width=device-width, initial- id="studentFormDirectorDiv">
scale=1.0" /> <button id="redirect">
<title>Login Page</title> <a href="./studentForm.html">I am a
<link rel="stylesheet" href="../css/login.css" /> student</a>
</head> </button>
<body> </div>
<div id="failedLogin">Invalid Credentials</div> </div>
<div id="connectionFailure"></div> </div>
<div class="outerContainerLogin"> <script src="../js/loginHandle.js"></script>
<div class="sideImageContainer"></div> </body>
<div class="formContainer"> </html>
<form id="loginForm">
<div id="header"><h1>User
Login</h1></div>
<div class="container"
id="usernameContainer">
<input
type="text"
placeholder="Username"
id="username"
name="username"
/>
</div>
<div class="container"
id="passwordContainer">
<input
type="password"
placeholder="Password"
id="password"
name="password"
/>
</div>
<div class="container" id="sessionDiv">
<input type="checkbox"
name="remember" id="remember" />
<label for="remember">Remember
Me</label>
</div>
<div class="container"
id="buttonContainer">
studentForm.html
<!DOCTYPE html> <div class="contentBox">
<html lang="en"> <div id="additionalAddressBox">
<head> <input
<meta charset="UTF-8" /> type="text"
<meta name="viewport" id="street"
content="width=device-width, initial- name="street"
scale=1.0" /> placeholder="Additional address
<title>Document</title> details"
<link rel="stylesheet" href="../css/style.css" />
</head> </div>
</div>
<body> </div>
<div id="successSubmit">Form Submitted
Successfully</div> <div class="innerHalf" id="rightHalf">
<div id="submitFailure">Details you tried to <div class="heading">
submit is invalid !</div> <h2>Contact Details</h2>
<div id="connectionFailure"></div> </div>
<div id="notAgreed"> <div class="contentOuter">
Can't submit form until you agree terms and <div class="contentBox">
conditions <div id="addressStateBox">
</div> <select name="state" id="state"
<!-- <div class="failedSubmit"></div> --> onchange="addDistricts()">
<form action="#" id="studentForm"> <option value="" disabled
<div class="outerContainerForm"> selected>Select Your State</option>
<div class="innerHalf" id="leftHalf"> <option value="Koshi">Koshi</option>
<div class="heading"> <option
<h2>General Information</h2> value="Madhesh">Madhesh</option>
</div> <option
<div class="contentOuter"> value="Bagmati">Bagmati</option>
<div class="contentBox"> <option
<div id="firstNameDiv"> value="Gandaki">Gandaki</option>
<input <option
type="text" value="Lumbini">Lumbini</option>
name="firstName" <option
id="firstName" value="Karnali">Karnali</option>
placeholder="First Name" <option
/> value="Sudurpaschim">Sudurpaschim</option>
</div> </select>
<div id="lastNameDiv"> </div>
<input </div>
type="text" <div class="contentBox">
name="lastName" <div id="districtSelectBox">
id="lastName" <select name="district" id="district">
placeholder="Last Name" <option value="" disabled selected>
/> Select Your District
</div> </option>
</div> <!-- This part will be dynamically
<div class="contentBox"> created using JavaScript -->
<div id="courseSelectBox"> </select>
<select name="course" id="course"> </div>
<option value="" disabled <div id="cityInputBox">
selected>Course</option> <input
<option value="CSIT">CSIT</option> type="text"
<option value="BBA">BBA</option> id="city"
<option value="BCA">BCA</option> name="city"
<option value="BIT">BIT</option> />
</select> </div>
</div> </div>
</div> <div class="contentBox"
<div class="contentBox"> id="emailAndPhone">
<div id="universityInputBox"> <div id="phoneNumberInputBox">
<input <input
type="text" type="text"
name="university" name="phone"
id="university" id="phone"
placeholder="University" placeholder="Phone Number"
/> />
</div> </div>
<div id="collegeDiv"> <div id="emailInputBox">
<input <input
type="text" type="email"
name="college" name="email"
id="college" id="email"
placeholder="College" placeholder="Your Email"
/> />
</div> </div>
</div> </div>
<div class="contentBox"> <div class="contentBox">
<div id="rollNumberBox"> <div id="termsAndConditions">
<input <input type="checkbox" id="agree"
type="text" value="agreed" />
id="rollNo" <label for="agree"
name="rollNo" >I do accept the terms and conditions
placeholder="Roll Number" of your site</label
/> >
</div> </div>
<div id="regNumberBox"> </div>
<input <div class="contentBox">
type="text" <div id="submitButtonBox">
id="regNo" <button type="submit"
name="regNo" name="submit">Submit Details</button>
placeholder="Registration Number" </div>
/> </div>
</div> </div>
placeholder="Village/Municipality" </div>
/> </div>
</div> </form>
</div> <script
src="../js/provienceAndDistrict.js"></script>
<script
src="../js/handleFormSubmission.js"></script>
</body>
</html>
header.css
@import url("https://fonts.googleapis.com/css2?
family=Montserrat:ital,wght@0,200;0,300;0,400;0,500;1,200;1,300&display=swap");

*{
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;
} }

.container > input {


border: none;
border-bottom: 1px solid grey;
background: transparent;
}
style.css
@import url(./header.css);
.contentBox input::placeholder,
body { .contentBox input,
display: flex; .contentBox select,
justify-content: center; .contentBox label {
align-items: center; font-size: 14px;
height: 100vh; }
background: rgb(154, 208, 194);
background: linear-gradient( #rightHalf .contentBox input::placeholder {
180deg, color: white;
rgba(154, 208, 194, 1) 58%, }
rgba(236, 244, 214, 1) 100%
); #rightHalf .contentBox #phoneNumberInputBox {
} width: 30%;
}
.outerContainerForm { #rightHalf .contentBox #emailInputBox {
display: flex; width: 65%;
justify-content: start; }
align-items: stretch;
width: 55vw; #rightHalf .contentBox #additionalAddressBox,
} #rightHalf .contentBox #addressStateBox,
#leftHalf .contentBox #courseSelectBox,
#studentForm { #rightHalf .contentBox #phoneNumberInputBox
border-radius: 10px; input,
box-shadow: -4px 6px 10px 1px rgba(0, 0, 0, #rightHalf .contentBox #emailInputBox input,
0.42); #rightHalf .contentBox #additionalAddressBox
-webkit-box-shadow: -4px 6px 10px 1px rgba(0, input,
0, 0, 0.42); #rightHalf .contentBox #addressStateBox select,
-moz-box-shadow: -4px 6px 10px 1px rgba(0, 0, #leftHalf .contentBox #courseSelectBox select {
0, 0.42); width: 100%;
} }

#leftHalf, #rightHalf .contentBox #termsAndConditions {


#rightHalf { display: flex;
flex: 1; justify-content: center;
} align-items: center;
}
#leftHalf {
background-color: white; #rightHalf .contentBox #termsAndConditions
padding: 40px 40px 40px 40px; input {
border-radius: 10px 0px 0px 10px; margin-right: 10px;
} }

#rightHalf { #rightHalf .contentBox #submitButtonBox {


padding: 40px 40px 40px 40px; padding-top: 10px;
background-color: #265073; }
color: white;
border-radius: 0px 10px 10px 0px; #rightHalf .contentBox button {
} padding: 5px 15px;
background-color: white;
#leftHalf > .heading { border: none;
color: #265073; border-radius: 20px;
} font-weight: bold;
color: #265073;
#rightHalf > .heading { }
color: white;
} #rightHalf .contentBox button:focus-visible {
outline: none;
.heading h2 { }
font-weight: 500;
font-size: 24px; #rightHalf .contentBox button:hover {
padding-bottom: 25px; cursor: pointer;
} transform: scale(1.01);
}
.contentOuter {
width: 100%; #rightHalf .contentBox select > option {
} background-color: #265073;
color: white;
.contentBox { font-size: 14px;
width: 100%; padding: 5px;
justify-content: space-between; }
display: flex;
padding-bottom: 20px; #successSubmit,
} #submitFailure,
#notAgreed,
.contentBox input, #connectionFailure {
.contentBox select { padding: 10px;
padding: 5px; border-radius: 10px;
border: none; position: absolute;
background-color: transparent; right: 10px;
} top: 10px;
transform: translateX(1000px);
#leftHalf .contentBox input, transition: transform 1000ms;
#leftHalf .contentBox select { /* color: white; */
border-bottom: 1px solid grey; }
}
#successSubmit {
.contentBox input:focus { background-color: #acf38c;
outline: none; }
}
#submitFailure,
#leftHalf .contentBox select { #notAgreed,
color: grey; #connectionFailure {
} background-color: #ff8888;
select:focus { color: white;
outline: none; font-weight: 500;
} /* visibility: hidden; */
}
#rightHalf .contentBox input,
#rightHalf .contentBox select { #notAgreed {
color: white; top: 55px;
border-bottom: 1px solid white; }
}
#connectionFailure {
top: 55px;
}

.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 submitForm() { if (!username.value || !


let loginForm = isUsername(username.value)) {
document.getElementById("loginForm"); errors.username = true;
}
let loginFormData = new FormData(loginForm);
loginFormData.append( if (!password.value || !
"doRemember", isPassword(password.value)) {
document.getElementById("remember").checked errors.password = true;
); }
fetch("../php/login.php", {
method: "POST", let valid = true;
body: loginFormData, for (key in errors) {
}) if (errors[key]) {
.then((response) => response.json()) valid = false;
.then((data) => { let errorMsg =
if (data.success) { document.getElementById("failedLogin");
// authentication successful, redirect the file to
the page with all the data document.getElementById(key).classList.add("e
window.location.href = data.redirectURL; rrorClass");
} else { errorMsg.style.transform = "translateX(0)";
if (data.error == "Incorrect Username") { setTimeout(function () {
handleFailure("username"); errorMsg.style.transform =
} else { "translateX(1000px)";
handleFailure("password"); }, 3000);
} } else {
}
}) document.getElementById(key).classList.remov
.catch((error) => { e("errorClass");
}
document.getElementById("connectionFailure").inn }
erHTML = error; return valid;
handleSlide("connectionFailure"); }
});
}

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",
];

You might also like