0% found this document useful (0 votes)
22 views4 pages

Iwd9 B 1

The document outlines the creation of a web page for employee login, consisting of an HTML form for username and password input. It includes a PHP script for handling the login process, which connects to a database, verifies the username and password, and starts a session for the authenticated user. If the credentials are invalid, appropriate error messages are displayed.

Uploaded by

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

Iwd9 B 1

The document outlines the creation of a web page for employee login, consisting of an HTML form for username and password input. It includes a PHP script for handling the login process, which connects to a database, verifies the username and password, and starts a session for the authenticated user. If the credentials are invalid, appropriate error messages are displayed.

Uploaded by

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

IWD 4340704

Practical-9(B)
Aim:- Create a web page for employee log-in.
Source Code:-
P9b.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Login</title>
</head>
<body>
<h2>Employee Login</h2>
<form action="p9b.php" method="post">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>

236470307054 77 | P a g e
IWD 4340704

P9b.php:
<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jay";
// // Create connection
$db = new mysqli($servername, $username, $password, $dbname);

if ($db->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = $_POST['username'];
$password = $_POST['password'];

$check_username = "SELECT id,username,password FROM employees WHERE


username ='$username' ";
$response = $db->query($check_username);
$udata = $response->fetch_assoc();
$id = $udata['id'];
if ($response->num_rows != 0) {
$check_password = "SELECT username,password FROM employees WHERE
username ='$username' AND password = '$password' ";
$response_password = $db->query($check_password);
if ($response_password->num_rows != 0) {
236470307054 78| P a g e
IWD 4340704
$emp = "SELECT * FROM employees WHERE id = '$id' ";
$data = $db->query($emp);
$employee = $data->fetch_assoc();
session_start();
$_SESSION['employee_id'] = $employee['id'];
$_SESSION['employee_name'] = $employee['username'];
$_SESSION['employee_email'] = $employee['email'];
$_SESSION['employee_phone'] = $employee['phone'];
$_SESSION['employee_position'] = $employee['position'];
$_SESSION['employee_salary'] = $employee['salary'];
header("Location: home.php");
exit();
} else {
echo "Invalid Password";
}
} else {
echo "Invalid username or password.";
}
$db->close();
?>

236470307054 79| P a g e
IWD 4340704

Output:

236470307054 80| P a g e

You might also like