You are on page 1of 19

SUNGAI LANG

45100 SUNGAI AYER TAWAR


SELANGOR

DIPLOMA IN INFORMATION TECHNOLOGY


( DIGITAL TECHNOLOGY )

WEB PROGRAMMING
( DFP 50193 )

PROBLEM BASED TASK 2

Prepared by :
MUHAMAD AKMAL BIN AZHAR ( 17DDT21F2022)
MUHAMMAD HAZIM BIN CHE HALIM (17DDT21F2026)

DDT4A

Lecturer
SIR AZROL HISHAM BIN MOHD ADHAM

Submission Date
23 NOVEMBER 2023
QUESTION PBT2
SOURCE CODE

LOGIN.PHP

<?php
session_start();

if (isset($_REQUEST['login'])) {
include 'conn.php';

$username = $_REQUEST['username'];
$password = $_REQUEST['password'];

$query_user = "SELECT * FROM register WHERE username = '$username' AND


password='$password'";
$result_user = mysqli_query($conn, $query_user);
$notempty = mysqli_num_rows($result_user);
$row = mysqli_fetch_assoc($result_user);
$active = $row['active'];
$role = $row['role'];
$name = $row['name'];
$_SESSION['name'] = $name;

if ($notempty == 0) {
?>
<script>
alert('You have not registered');
window.location='register.php';
</script>
<?php
} else {
// IF USER REGISTER AND LOGIN BUT NOT YET ACTIVE BY ADMIN
if ($active==0)
{
?>
<script>alert('Your account has not been approved. Please
contact the administrator for approval.');
window.location='login.php';</script>
<?php
}
// IF USER LOGIN AND REGISTER AS A STUDENT
else if ($role=="STUDENT")
{
?>
<script> window.location='student.php';</script>
<?php
}
// IF USER LOGIN AND REGISTER AS A LECTURER
else if ($role=="LECTURER")
{
?>
<script> window.location='lecturer.php';</script>
<?php
}
// IF USER LOGIN AND REGISTER AS A ADMIN
else if ($role=="ADMIN")
{
?>
<script> window.location='admin.php';</script>
<?php
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4; /* Background color for the entire page */
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh; /* Full height of the viewport */
}

.login-container {
width: 300px;
background-color: #fff; /* Background color for the container */
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Box shadow for a subtle
elevation effect */
padding: 20px;
box-sizing: border-box; /* Include padding and border in the element's
total width and height */
}

input {
width: 100%;
padding: 10px;
margin: 8px 0; /* Increased margin for better spacing */
box-sizing: border-box;
border: 1px solid #ccc; /* Border to separate input fields */
border-radius: 5px;
}

button {
width: 100%;
padding: 10px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
</style>

</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form action="login.php" method="post">
<label for="username">Username:</label>
<input type="text" name="username" required>

<label for="password">Password:</label>
<input type="password" name="password" required>

<input type="submit" name="login">


</form>
</div>
</body>
</html>
REGISTER.PHP

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Page</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.form-container {
background-color: #fff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 300px;
text-align: center;
}

input {
width: 100%;
padding: 10px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}

select {
width: 100%;
padding: 10px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
width: 100%;
padding: 10px;
background-color: #4caf50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>

<body>
<div class="form-container">
<h2>Registration Form</h2>
<form method="post" action="conn_register.php">
<label for="username">Username:</label>
<input type="text" name="username" id="username">

<label for="password">Password:</label>
<input type="password" name="password" id="password">

<label for="name">Name:</label>
<input type="text" name="name" id="name">

<label for="icno">IC No:</label>


<input type="text" name="icno" id="icno">

<label for="role">Role:</label>
<select name="role" id="role">
<option value="STUDENT">Student</option>
<option value="LECTURER">Lecturer</option>
<option value="ADMIN">Admin</option>
</select>

<button type="submit" name="submit">Register</button>


</form>
</div>
</body>
</html>
CONN_REGISTER.PHP

<?php
session_start();
?>

<html lang="en">
<head>

</head>
<body>
<?php
// CONNECTION PAGE
include 'conn.php';

// GET THE VALUE FROM THE REGISTER PAGE


$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$name = $_REQUEST['name'];
$icno = $_REQUEST['icno'];
$role = $_REQUEST['role'];

// Check if the IC number already exists in the database


$query = "SELECT * FROM register WHERE icno = '$icno'";
$result = mysqli_query($conn, $query);

if (mysqli_num_rows($result) > 0) {
// IC number already exists
?>
<script>
alert('IC number already registered. Please choose a different IC
number.');
window.location='register.php';
</script>
<?php
} else {
// IC number is unique, proceed with registration
// INSERT INFO TO THE DATABASE
$sql = "INSERT INTO register (username, password, name, icno, role)
VALUES ('$username', '$password', '$name', '$icno', '$role')";

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


// Successful insert
?>
<script>
alert('You have been registered');
window.location='login.php';
</script>
<?php
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}

$conn->close();
?>
</body>
</html>

CONN.PHP

<?php
$conn = new mysqli("localhost:3306", "root", "", "pbt2");

if (!$conn){
die(mysqli_error($conn));
}
?>

STUDENT.PHP

<?php
session_start()
?>

<html lang="en">
<head>
<style>
body {
font-family: 'Arial', sans-serif;
text-align: center;
margin: 50px;
background-color: #f4f4f4; /* Background color for the entire page */
}

h2, h3 {
color: #333;
}

.name {
padding-top: 30px;
font-size: 20px;
font-weight: bold;
color: #0066cc;
}

input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px;
margin: 10px 0; /* Increased margin for better spacing */
box-sizing: border-box;
border: 1px solid #ccc; /* Border for input fields */
border-radius: 20px;
}

input[type="submit"] {
background-color: #007BFF;
color: #fff;
border: none;
padding: 12px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 20px;
cursor: pointer;
transition: background-color 0.3s; /* Smooth transition for hover
effect */
}

input[type="submit"]:hover {
background-color: #0056b3;
}
</style>

</head>
<body>
<h2>WELCOME TO DEPARTMENT OF INFORMATION TECHNOLOGY AND
COMMUNICATION<br><br>STUDENT PAGE</h2>
<h3>
<?php
echo "<span class='name'>WELCOME BACK ", $login = $_SESSION['name'],
"</span>";
if ($login == "") {
?>
<script> window.location='login.php';</script>
<?php
}
?>
</h3>
<form method="post">
<center><input type="submit" name="logout" value="Logout"
class="button"></center>
</form>

<?php
if(isset($_REQUEST['logout'])){
session_destroy();
?>
<script> window.location='login.php';</script>
<?php
}
?>
</body>
</html>

LECTURER.PHP

<?php
session_start();
?>

<html lang="en">
<head>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 0;
background-color: #f4f4f4;
}

h2, h3 {
text-align: center;
color: #333;
}

.name {
margin-top:50px;
font-size:20px;
font-weight: bold;
color: #0066cc;
}

input[type="submit"] {
background-color: #007BFF;
color: #fff;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius:20px;
cursor: pointer;
}

input[type="submit"]:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h2>WELCOME TO DEPARTMENT OF INFORMATION TECHNOLOGY AND
COMMUNICATION<br><br>LECTURER PAGE</h2>

<h3>
<?php
echo "<span class='name'>WELCOME BACK ", $login = $_SESSION['name'],
"</span>";
if ($login == "") {
?>
<script> window.location='login.php';</script>
<?php
}
?>
</h3>

<center>
<form method="post">
<input type="submit" name="logout" value="Logout" class="button"
/>
</form>
</center>

<?php
if (isset($_REQUEST['logout'])) {
// DESTROY THE SESSION
session_destroy();
?>
<script> window.location='login.php';</script>
<?php
}
?>
</body>
</html>
ADMIN.PHP

<?php
session_start();
?>

<html lang="en">
<head>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 0;
background-color: #f4f4f4;
}

h2, h3 {
text-align: center;
color: #333;
}

.name {
margin-top:50px;
font-size:20px;
font-weight: bold;
color: #0066cc;
}

input[type="submit"] {
background-color: #007BFF;
color: #fff;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius:20px;
cursor: pointer;
}

input[type="submit"]:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h2>WELCOME TO DEPARTMENT OF INFORMATION TECHNOLOGY AND
COMMUNICATION<br><br>LECTURER PAGE</h2>

<h3>
<?php
echo "<span class='name'>WELCOME BACK ", $login = $_SESSION['name'],
"</span>";
if ($login == "") {
?>
<script> window.location='login.php';</script>
<?php
}
?>
</h3>

<center>
<form method="post">
<input type="submit" name="logout" value="Logout" class="button"
/>
</form>
</center>

<?php
if (isset($_REQUEST['logout'])) {
// DESTROY THE SESSION
session_destroy();
?>
<script> window.location='login.php';</script>
<?php
}
?>
</body>
</html>
OUTPUT

LOGIN.PHP
REGISTER.PHP

ADMIN.PHP
STUDENT.PHP

LECTURER.PHP

MYSQL
RUBRIC

You might also like