0% found this document useful (0 votes)
15 views

Gate

The documents contain PHP code and HTML markup for building a user management system with features like adding users, viewing a user list, and tracking visitor check-ins and check-outs. The code includes form handling, database connections, and querying user and visitor data.

Uploaded by

ombenimichael20
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)
15 views

Gate

The documents contain PHP code and HTML markup for building a user management system with features like adding users, viewing a user list, and tracking visitor check-ins and check-outs. The code includes form handling, database connections, and querying user and visitor data.

Uploaded by

ombenimichael20
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/ 63

Add_user.

php

<?php
// Retrieve the form data
$username = $_POST['username'];
$password = $_POST['password'];

// Replace the placeholder values with your actual database credentials


$host = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $dbUsername, $dbPassword, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Prepare the SQL statement to insert the user into the table
$sql = "INSERT INTO users (username, password) VALUES ('$username',
'$password')";

// Execute the SQL statement


if ($connection->query($sql) === TRUE) {
echo 'User added successfully';
} else {
echo 'Error: ' . $sql . '<br>' . $connection->error;
}

// Close the database connection


$connection->close();
?>

addUser.html

<!DOCTYPE html>
<html>
<head>
<title>User Management</title>
<style>
/* CSS styles */
body {
background-color: #f5f5f5;
font-family: Arial, sans-serif;
}

h2 {
color: #333;
}

table {
border-collapse: collapse;
width: 100%;
}

th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}

th {
background-color: #f2f2f2;
font-weight: bold;
}

button {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<!-- Add User Form -->
<h2>Add User</h2>
<form id="add-user-form" action="add_user.php" method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>

<label for="user-type">User Type:</label>


<select id="user-type" name="user-type">
<option value="user">User</option>
<option value="admin">Admin</option>
<option value="employee">Employee</option>
</select>

<button type="submit">Add User</button>


</form>

<!-- User List -->


<h2>User List</h2>
<table id="user-list">
<thead>
<tr>
<th>Username</th>
<th>Password</th>
<th>Action</th>
<th>User Type</th>
</tr>
</thead>
<tbody>

</tbody>
</table>

<script src="script.js"></script>
</body>
</html>

Admin.html

<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
padding: 20px;
background-image: url('image/visitor.jpg');
background-size: cover;
}

header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0;
background-color: #cc582e;
}

nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}

nav ul li {
display: inline;
margin-right: 10px;
}

nav ul li a {
text-decoration: none;
color: #130997;
padding: 5px;
}

nav ul li a:hover {
background-color: #2d0daf;
}

h1 {
text-align: center;
color: rgb(30, 31, 30);
}

p {
text-align: center;
color: rgb(5, 5, 5);
}

footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #1d55cf;
padding: 10px 0;
text-align: center;
color: white;
}

.content {
max-width: 50%;
margin: 0 auto;
background-color: rgba(164, 85, 37, 0.8);
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.image-container {
display: flex;
justify-content: center;
margin-top: 20px;
}

.image-container img {
width: 200px;
height: 200px;
object-fit: cover;
border-radius: 50%;
}
</style>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#">HOME</a></li>
<li><a href="details.html">REGISTER</a></li>
<li><a href="total_card.php">vCARDS</a></li>
<li><a href="visitor_stutus.php">VSTATUS</a></li>
<li><a href="visitors_total.php">REPORT</a></li>

<li><a id="aboutUsLink" href="#">ABOUTUS</a></li>


</ul>
</nav>
</header>

<div class="content">
<h1>ARDHI UNIVERSITY VISITORS RECORD</h1>
<p>WELCOME VISITOR</p>
</div>

</div>

</div>

<footer>
&copy; SR12.
</footer>

<script>
// JavaScript code to show and hide the additional information
document.addEventListener('DOMContentLoaded', function() {
const aboutUsLink = document.getElementById('aboutUsLink');
const additionalInfo = document.getElementById('additionalInfo');

aboutUsLink.addEventListener('click', function(e) {
e.preventDefault();
additionalInfo.classList.toggle('hidden');
});
});
</script>
</body>
</html>

adminPage.html

<!DOCTYPE html>
<html>
<head>
<title>Admin Dashboard</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
padding: 20px;
background-image: url('image/admin.jpg');
background-size: cover;
}

h1 {
color: blue;
text-align: center;
}

.dashboard {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 20px;
margin-top: 40px;
}

.card {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.card h2 {
color: blue;
margin-bottom: 10px;
}

.card p {
margin: 0;
}
</style>
</head>
<body>
<h1>Welcome, Admin</h1>

<div class="dashboard">
<a href="report.php" class="card">
<h2>Total Visitors</h2>

</a>
<a href="adduser.html" class="card">
<h2>USERS</h2>

</a>
<a href="visitors_total.php" class="card">
<h2>REPORT</h2>

</a>
</a>
<a href="visitor_stutus.php" class="card">
<h2>VSTATUS</h2>

</a>
</div>
</body>
</html>

Busser.php

<!DOCTYPE html>
<html>
<head>
<title>Welcome Page</title>
</head>
<style>
/* CSS styles */
body {
background-color: yellow;
font-family: Arial, sans-serif;
}

h1 {
color: green;
}
</style>
<body>
<h1>VISITOR STATUS</h1>

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Check if the form is submitted for filling out the checkout time
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$visitorId = $_POST['visitor-id'];
$timeOut = $_POST['time-out'];

// Prepare an SQL statement to update the checkout time for the visitor
$sql = "UPDATE visitors SET time_out = ? WHERE id = ?";
$stmt = $connection->prepare($sql);

// Bind the form data to the SQL statement


$stmt->bind_param("si", $timeOut, $visitorId);

// Execute the prepared statement


if ($stmt->execute()) {
echo "";
} else {
// Handle the case where the statement execution fails
echo "Error updating checkout time: " . $stmt->error;
}

// Close the prepared statement


$stmt->close();
}

// Retrieve the visitor records from the database


$sql = "SELECT * FROM visitors";
$result = $connection->query($sql);

// Check if any visitor records exist


if ($result->num_rows > 0) {
// Output the visitor status and provide a form for filling out the
checkout time
while ($row = $result->fetch_assoc()) {
$visitorId = $row['id'];
$name = $row['first_name'] . ' ' . $row['last_name'];
$checkInDateTime = $row['time_in'];
$checkOutTime = $row['time_out'];
$status = ($checkOutTime != null) ? 'Checked Out' : 'Checked In';
$office = $row['office'];

// Extract the date and time from the check-in datetime value
$checkInDate = date('Y-m-d', strtotime($checkInDateTime));
$checkInTime = date('H:i:s', strtotime($checkInDateTime));

echo "Name: " . $name . "<br>";


echo "Office: " . $office . "<br>";
echo "Check-in Date: " . $checkInDate . "<br>";
echo "Check-in Time: " . $checkInTime . "<br>";
echo "Check-out Time: " . $checkOutTime . "<br>";
echo "Status: " . $status . "<br>";

// Display the form for filling out the checkout time


if ($status === 'Checked In') {
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?
>">
<input type="hidden" name="visitor-id" value="<?php echo
$visitorId; ?>">
<label for="time-out">Checkout Time:</label>
<input type="datetime-local" id="time-out" name="time-out">
<button type="submit">Fill Out Checkout</button>
</form>
<?php
}

echo "<br><br>";
}
} else {
echo "No visitor records found.";
}

// Close the database connection


$connection->close();
?>

</body>
</html>

Checkout.php

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Retrieve form data from $_POST or other relevant source


$visitorId = $_POST['visitor-id'];
$timeOut = $_POST['time-out'];

// Prepare an SQL statement to update the checkout time for the visitor
$sql = "UPDATE visitors SET time_out = ? WHERE id = ?";
$stmt = $connection->prepare($sql);

// Bind the form data to the SQL statement


$stmt->bind_param("si", $timeOut, $visitorId);

// Execute the prepared statement


if ($stmt->execute()) {
$updateVisitorNumberSql = "UPDATE visitors SET visitor_number =
visitor_number - 1 WHERE id = ?";
$stmt2 = $connection->prepare($updateVisitorNumberSql);
$stmt2->bind_param("i", $visitorId);
$stmt2->execute();
$stmt2->close();
header("Location: visitor-status.php");
exit();
} else {
// Handle the case where the statement execution fails
echo "Error: " . $stmt->error;
}

// Close the prepared statement and database connection


$stmt->close();
$connection->close();
?>

Delete_user.php

<?php
// Retrieve the user ID from the query parameter
$userId = $_GET['id'];

// Replace the placeholder values with your actual database credentials


$host = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $dbUsername, $dbPassword, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Prepare the SQL statement to delete the user from the table
$sql = "DELETE FROM users WHERE id = $userId";

// Execute the SQL statement


if ($connection->query($sql) === TRUE) {
echo 'User deleted successfully';
} else {
echo 'Error: ' . $sql . '<br>' . $connection->error;
}

// Close the database connection


$connection->close();
?>

Details.html

<!DOCTYPE html>
<html>
<head>
<title>Enter Visitor Details</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
background-image: url("image/id.jpg");
background-size: cover;
background-position: center;
}

h1 {
color: blue;
text-align: center;
font-family: Arial, sans-serif;
}

form {
background-color: #fff;
padding: 9px;
border-radius: 4px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
max-width: 300px;
margin: 0 auto;
}

label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}

input[type="text"],
input[type="time"],
textarea,
select {
width: 100%;
padding: 4px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-bottom: 6px;
}

input[type="submit"],
input[type="button"] {
background-color: yellow;
color: blue;
padding: 4px 8px;
border: none;
border-radius: 4px;
cursor: pointer;
}

input[type="submit"]:hover,
input[type="button"]:hover {
background-color: green;
}

.horizontal-line {
border-top: 1px solid #ccc;
margin: 8px 0;
}

/* Rest of your CSS code */

</style>
<script>
// JavaScript code
var visitorNumbers = {
busser: 0,
masijala: 0,
dup: 0,
dean: 0
};

function updateVisitorNumber() {
var officeSelect = document.getElementById("office");
var visitorNumberInput = document.getElementById("visitor-number");
var selectedOption = officeSelect.value;

if (selectedOption) {
visitorNumbers[selectedOption]++;
visitorNumberInput.value =
selectedOption.charAt(0).toUpperCase() + visitorNumbers[selectedOption];
} else {
visitorNumberInput.value = "";
}
}

window.onload = function() {
var dateTimeNow = new Date().toISOString().slice(0, 16);
var timeInInput = document.getElementById("time-in");
timeInInput.value = dateTimeNow;
};
</script>
</head>
<body>
<h1>ENTER VISITOR DETAILS</h1>

<form action="save.php" method="POST">


<label for="first-name">First Name:</label>
<input type="text" id="first-name" name="first-name" required>

<label for="last-name">Last Name:</label>


<input type="text" id="last-name" name="last-name" required>

<label for="phone">Phone Number:</label>


<input type="text" id="phone" name="phone" required>

<label for="office">Office Number:</label>


<select id="office" name="office" onchange="updateVisitorNumber()"
required>
<option value="">Select office</option>
<option value="busser">Busser</option>
<option value="masijala">Masijala</option>
<option value="dup">Dup</option>
<option value="dean">Dean</option>
</select>

<label for="visitor-number">Visitor Number:</label>


<input type="text" id="visitor-number" name="visitor-number" readonly>

<label for="address">Address:</label>
<textarea id="address" name="address" required></textarea>

<label for="time-in">Time In:</label>


<input type="datetime-local" id="time-in" name="time-in" required>

<div class="horizontal-line"></div>

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


<input type="button" value="Cancel"
onclick="window.location.href='admin.html'">
</form>
</body>
</html>

Get_users.php

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $dbUsername, $dbPassword, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Prepare the SQL statement to select all users


$sql = "SELECT * FROM users";
$result = $connection->query($sql);

// Check if the query was successful


if ($result && $result->num_rows > 0) {
$users = array();
while ($row = $result->fetch_assoc()) {
$users[] = array(
'id' => $row['id'],
'username' => $row['username'],
'password' => $row['password']
);
}

// Return the user list as JSON


echo json_encode($users);
} else {
// No results found
echo 'No users found.';
}

// Close the database connection


$connection->close();
?>

Index.php

<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: orange;
}

h1 {
text-align: center;
color: pupple;
}

form {
max-width: 300px;
margin: 0 auto;
padding: 20px;
background-color: blue;
color: white;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}

input[type="text"],
input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-bottom: 15px;
}

select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-bottom: 15px;
}

input[type="submit"] {
background-color: yellow;
color: blue;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}

input[type="submit"]:hover {
background-color: green;
}
</style>
</head>
<body>
<h1>Login</h1>
<form action="login.php" method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>

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

<label for="user-type">Select user type:</label>


<select id="user-type" name="user-type">
<option value="user">User</option>
<option value="admin">Admin</option>
<option value="employee">Employee</option>
</select><br><br>

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


</form>
</body>
</html>

Login.php

<?php
session_start();

// Assuming you have already established a database connection


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myapp";

// Create a new mysqli connection


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

// Check the connection


if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}

// Get the username, password, and user type from the login form
$username = $_POST['username'];
$password = $_POST['password'];
$userType = $_POST['user-type'];

// Perform a query to check if the user exists in the database


$query = "SELECT * FROM users WHERE username = '$username' AND password =
'$password' AND user_type = '$userType'";
$result = mysqli_query($connection, $query);

// Check if there is a result


if ($result && mysqli_num_rows($result) > 0) {
// User authenticated, store user details in session
$user = mysqli_fetch_assoc($result);
$_SESSION['user'] = $user;

// Redirect to the appropriate page based on user type


if ($userType === 'user') {
header("Location: admin.html");
exit();
} elseif ($userType === 'admin') {
header("Location: adminpage.html");
exit();
} elseif ($userType === 'employee') { // Add the employee condition
header("Location: busser.php");
exit();
}
} else {
// User authentication failed, redirect back to login page
header("Location: index.php");
exit();
}
// Close the database connection
mysqli_close($connection);
?>

Receipt.php

<!DOCTYPE html>
<html>
<head>
<title>VISITOR CARD</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}

.receipt-container {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
max-width: 300px;
margin: 0 auto;
}

.receipt-item {
margin-bottom: 10px;
}

.receipt-label {
font-weight: bold;
display: block;
}

.receipt-value {
margin-top: 5px;
}

.action-buttons {
text-align: center;
margin-top: 20px;
}

.action-buttons button {
padding: 10px 20px;
background-color: yellow;
color: blue;
border: none;
border-radius: 4px;
margin-right: 10px;
}

.action-buttons button.cancel {
background-color: #ccc;
color: #333;
}
</style>
</head>
<body>
<div class="receipt-container">
<h1>VISITOR CARD</h1>

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Prepare an SQL statement to retrieve the most recent form data from
the database
$sql = "SELECT * FROM visitors ORDER BY id DESC LIMIT 1";
$result = $connection->query($sql);

// Check if the query was successful


if ($result && $result->num_rows > 0) {
// Fetch the row
$row = $result->fetch_assoc();
} else {
// No results found
echo "No receipt found.";
}

// Close the database connection


$connection->close();
?>

<?php if (isset($row)) : ?>


<div class="receipt-item">
<span class="receipt-label">Name:</span>
<span class="receipt-value"><?php echo $row['first_name'] . '
' . $row['last_name']; ?></span>
</div>

<div class="receipt-item">
<span class="receipt-label">Phone:</span>
<span class="receipt-value"><?php echo $row['phone']; ?></span>
</div>

<div class="receipt-item">
<span class="receipt-label">Office:</span>
<span class="receipt-value"><?php echo $row['office']; ?></span>
</div>

<div class="receipt-item">
<span class="receipt-label">Visitor Number:</span>
<span class="receipt-value"><?php echo $row['visitor_number']; ?
></span>
</div>

<div class="receipt-item">
<span class="receipt-label">Address:</span>
<span class="receipt-value"><?php echo $row['address']; ?
></span>
</div>

<div class="receipt-item">
<span class="receipt-label">Time In:</span>
<span class="receipt-value"><?php echo $row['time_in']; ?
></span>
</div>

<div class="action-buttons">
<button onclick="window.print()">Print Card</button>
<button class="cancel"
onclick="window.location.href='admin.html'">Cancel</button>
</div>

<?php endif; ?>


</div>
</body>
</html>

Report.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myapp";

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

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Retrieve all visitors


$sql = "SELECT * FROM visitors";
$result = $conn->query($sql);

// Store the visitors in an array


$visitors = array();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$visitors[] = $row;
}
}

$conn->close();
?>

<!DOCTYPE html>
<html>
<head>
<title>Visitors List</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}

h1 {
color: blue; /* Change title color to blue */
text-align: center; /* Center align the heading */
}

table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}

th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}

th {
background-color: #f2f2f2;
}

</style>
<script>
function exitVisitor(visitorId) {
// Send an AJAX request to update the visitor's exit time in the
database
var xhr = new XMLHttpRequest();
xhr.open('POST', 'update_exit.php');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-
urlencoded');
xhr.onload = function() {
if (xhr.status === 200) {
location.reload(); // Refresh the page after successful
update
}
};
xhr.send('visitorId=' + visitorId);
}
</script>
</head>
<body>
<h1>Visitors List</h1>

<table>
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Office Number</th>
<th>Visitor Number</th>
<th>Address</th>

</tr>
</thead>
<tbody>
<?php foreach ($visitors as $visitor): ?>
<tr>
<td><?php echo $visitor["id"]; ?></td>
<td><?php echo $visitor["first_name"]; ?></td>
<td><?php echo $visitor["last_name"]; ?></td>
<td><?php echo $visitor["phone"]; ?></td>
<td><?php echo $visitor["office"]; ?></td>
<td><?php echo $visitor["visitor_number"]; ?></td>
<td><?php echo $visitor["address"]; ?></td>

</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>

Save.php

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Retrieve form data from $_POST or other relevant source


$firstName = $_POST['first-name'];
$lastName = $_POST['last-name'];
$phone = $_POST['phone'];
$office = $_POST['office'];
$visitorNumber = $_POST['visitor-number'];
$address = $_POST['address'];
$timeIn = $_POST['time-in'];

// Prepare an SQL statement to insert the form data into the database
$sql = "INSERT INTO visitors (first_name, last_name, phone, office,
visitor_number, address, time_in) VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmt = $connection->prepare($sql);

// Bind the form data to the SQL statement


$stmt->bind_param("ssssiss", $firstName, $lastName, $phone, $office,
$visitorNumber, $address, $timeIn);

// Execute the prepared statement


if ($stmt->execute()) {
$updateVisitorNumberSql = "UPDATE visitors SET visitor_number =
visitor_number + 1 WHERE office = '$office'";
$connection->query($updateVisitorNumberSql);
$lastInsertedId = $stmt->insert_id;
header("Location: receipt.php?id=$lastInsertedId");
exit();
} else {
// Handle the case where the statement execution fails
echo "Error: " . $stmt->error;
}

// Close the prepared statement and database connection


$stmt->close();
$connection->close();
?>

Scripts.js

// Fetch the user list from the server and populate the table
function fetchUserList() {
var userListContainer = document.getElementById('user-list');
var tbody = userListContainer.querySelector('tbody');
tbody.innerHTML = ''; // Clear existing table rows

// Send an AJAX request to get the user list


var xhr = new XMLHttpRequest();
xhr.open('GET', 'get_users.php', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var users = JSON.parse(xhr.responseText);

// Populate the table rows


for (var i = 0; i < users.length; i++) {
var user = users[i];
var row = '<tr>' +
'<td>' + user.username + '</td>' +
'<td>' + user.password + '</td>' +
'<td>' + user.user_type + '</td>' +
'<td><button class="delete-user" data-user-id="' + user.id +
'">Delete</button></td>' +
'</tr>';
tbody.innerHTML += row;
}

// Attach event listeners to the delete buttons


var deleteButtons =
userListContainer.getElementsByClassName('delete-user');
for (var j = 0; j < deleteButtons.length; j++) {
deleteButtons[j].addEventListener('click', deleteUser);
}
}
};
xhr.send();
}

// Event listener for the add user form submission


document.getElementById('add-user-form').addEventListener('submit',
function(event) {
event.preventDefault(); // Prevent form submission

var username = document.getElementById('username').value;


var password = document.getElementById('password').value;
var userType = document.getElementById('user-type').value;

// Send an AJAX request to add the user


var xhr = new XMLHttpRequest();
xhr.open('POST', 'add_user.php', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// Clear the form inputs
document.getElementById('username').value = '';
document.getElementById('password').value = '';

// Fetch the updated user list


fetchUserList();
}
};
xhr.send('username=' + encodeURIComponent(username) + '&password=' +
encodeURIComponent(password) + '&user-type=' + encodeURIComponent(userType));
});

// Event listener for the delete user buttons


function deleteUser(event) {
var userId = event.target.getAttribute('data-user-id');

// Send an AJAX request to delete the user


var xhr = new XMLHttpRequest();
xhr.open('GET', 'delete_user.php?id=' + userId, true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
// Fetch the updated user list
fetchUserList();
}
};
xhr.send();
}

// Fetch the initial user list on page load


fetchUserList();

total_card.php
<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Check if a specific day is requested


if (isset($_GET['date'])) {
$requestedDate = $_GET['date'];
} else {
// If no specific day is requested, use today's date
$requestedDate = date('Y-m-d');
}

// Prepare an SQL statement to retrieve the receipts for the requested date
$sql = "SELECT * FROM visitors WHERE DATE(time_in) = '$requestedDate' ORDER BY
time_in ASC";
$result = $connection->query($sql);

// Check if the query was successful


if ($result && $result->num_rows > 0) {
// Fetch all rows as an associative array
$receipts = $result->fetch_all(MYSQLI_ASSOC);
} else {
// No results found
$receipts = array();
}

// Close the database connection


$connection->close();
?>

<!DOCTYPE html>
<html>
<head>
<title>View Cards</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}

h1 {
color: blue;
text-align: center;
}

.receipts-container {
background-color: #fff;
padding: 10px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
max-width: 800px;
margin: 0 auto;
}

.receipt-item {
margin-bottom: 10px;
padding: 10px;
border: 1px solid #ccc;
}

.receipt-label {
font-weight: bold;
margin-right: 5px;
}

.action-buttons {
text-align: center;
margin-top: 10px;
}

.action-buttons button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
margin-right: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="receipts-container">
<h1>Cards for <?php echo $requestedDate; ?></h1>

<?php if (!empty($receipts)) : ?>


<?php foreach ($receipts as $receipt) : ?>
<div class="receipt-item">
<div>
<span class="receipt-label">First Name:</span>
<span><?php echo $receipt['first_name']; ?></span>
</div>

<div>
<span class="receipt-label">Last Name:</span>
<span><?php echo $receipt['last_name']; ?></span>
</div>

<div>
<span class="receipt-label">Phone Number:</span>
<span><?php echo $receipt['phone']; ?></span>
</div>

<div>
<span class="receipt-label">Office Number:</span>
<span><?php echo $receipt['office']; ?></span>
</div>

<div>
<span class="receipt-label">Visitor Number:</span>
<span><?php echo $receipt['visitor_number']; ?></span>
</div>

<div>
<span class="receipt-label">Address:</span>
<span><?php echo $receipt['address']; ?></span>
</div>

<div>
<span class="receipt-label">Time In:</span>
<span><?php echo $receipt['time_in']; ?></span>
</div>
<div class="action-buttons">
<button onclick="window.print()">Print</button>
</div>
</div>
<?php endforeach; ?>
<?php else : ?>
<p>No cards found for <?php echo $requestedDate; ?>.</p>
<?php endif; ?>
</div>
</body>
</html>

Update_exist.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myapp";

// Retrieve the visitor ID from the POST request


$visitorId = $_POST['visitorId'];

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

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Retrieve the visitor record


$sql = "SELECT * FROM visitors WHERE id = $visitorId";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// Visitor record found
$visitor = $result->fetch_assoc();

// Retrieve the current date and time


$exitTime = date('Y-m-d H:i:s');

// Update the visitor record with the exit time


$updateSql = "UPDATE visitors SET check_out_time = '$exitTime' WHERE id =
$visitorId";

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


echo "Visitor exit recorded successfully!";
} else {
echo "Error updating record: " . $conn->error;
}
} else {
echo "Visitor record not found!";
}

$conn->close();
?>

Validate.php

<?php

include_once('connection.php');

function test_input($data) {

$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

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

$username = test_input($_POST["username"]);
$password = test_input($_POST["password"]);
$stmt = $conn->prepare("SELECT * FROM adminlogin");
$stmt->execute();
$users = $stmt->fetchAll();

foreach($users as $user) {

if(($user['username'] == $username) &&


($user['password'] == $password)) {
header("location: admin.html");
}
else {
echo "<script language='javascript'>";
echo "alert('WRONG INFORMATION')";
echo "</script>";
die();
}
}
}

?>

Visitor_status.php

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Check if the form is submitted for filling out the checkout time
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$visitorId = $_POST['visitor-id'];
$timeOut = $_POST['time-out'];

// Prepare an SQL statement to update the checkout time for the visitor
$sql = "UPDATE visitors SET time_out = ? WHERE id = ?";
$stmt = $connection->prepare($sql);

// Bind the form data to the SQL statement


$stmt->bind_param("si", $timeOut, $visitorId);

// Execute the prepared statement


if ($stmt->execute()) {
echo "";
} else {
// Handle the case where the statement execution fails
echo "Error updating checkout time: " . $stmt->error;
}

// Close the prepared statement


$stmt->close();
}

// Retrieve the visitor records from the database


$sql = "SELECT * FROM visitors";
$result = $connection->query($sql);

// Check if any visitor records exist


if ($result->num_rows > 0) {
// Display the visitor records in a table format
echo "<table>";
echo "<tr><th>Name</th><th>Address</th><th>Office</th><th>Check-in
Time</th><th>Check-out Time</th><th>Status</th></tr>";

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


$visitorId = $row['id'];
$name = $row['first_name'] . ' ' . $row['last_name'];
$address = $row['address'];
$office = $row['office'];
$checkInTime = $row['time_in'];
$checkOutTime = $row['time_out'];
$status = ($checkOutTime != null) ? 'Checked Out' : 'Checked In';

echo "<tr>";
echo "<td>$name</td>";
echo "<td>$address</td>";
echo "<td>$office</td>";
echo "<td>$checkInTime</td>";
echo "<td>$checkOutTime</td>";
echo "<td>$status</td>";
echo "</tr>";
}

echo "</table>";
} else {
echo "No visitor records found.";
}

// Close the database connection


$connection->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Visitor Status</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}

table {
border-collapse: collapse;
width: 100%;
margin-bottom: 20px;
}

th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}

th {
background-color: #f2f2f2;
}
</style>
</head>
</html>

Visitors_total.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myapp";

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

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Retrieve total visitors per office


$sql = "SELECT office, COUNT(*) AS total_visitors FROM visitors GROUP BY office";
$result = $conn->query($sql);

// Store the totals in an array


$totals = array();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$totals[$row["office"]] = $row["total_visitors"];
}
}

$conn->close();
?>

<!DOCTYPE html>
<html>
<head>
<title>Visitor Totals</title>
<style>
/* CSS styles */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}

h1 {
color: blue; /* Change title color to blue */
text-align: center; /* Center align the heading */
}

table {
width: 50%;
margin: 0 auto;
border-collapse: collapse;
margin-bottom: 20px;
}

th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}

th {
background-color: #f2f2f2;
}

/* Add background photo */


body {
background-image: url("background.jpg");
background-size: cover;
background-position: center;
}
</style>
</head>
<body>
<h1>Visitor Totals</h1>

<table>
<thead>
<tr>
<th>Office</th>
<th>Total Visitors</th>
</tr>
</thead>
<tbody>
<?php foreach ($totals as $office => $totalVisitors): ?>
<tr>
<td><?php echo $office; ?></td>
<td><?php echo $totalVisitors; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>

Buser.php

<!DOCTYPE html>
<html>
<head>
<title>Welcome Page</title>
</head>
<body>
<h1>Welcome to Busser</h1>

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Check if the form is submitted for filling out the checkout time
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$visitorId = $_POST['visitor-id'];
$timeOut = $_POST['time-out'];

// Prepare an SQL statement to update the checkout time for the visitor
$sql = "UPDATE visitors SET time_out = ? WHERE id = ?";
$stmt = $connection->prepare($sql);

// Bind the form data to the SQL statement


$stmt->bind_param("si", $timeOut, $visitorId);

// Execute the prepared statement


if ($stmt->execute()) {
echo "Checkout time updated successfully.";
} else {
// Handle the case where the statement execution fails
echo "Error updating checkout time: " . $stmt->error;
}

// Close the prepared statement


$stmt->close();
}

// Retrieve the visitor records from the database


$sql = "SELECT * FROM visitors";
$result = $connection->query($sql);
// Check if any visitor records exist
if ($result->num_rows > 0) {
// Output the visitor status and provide a form for filling out the
checkout time
while ($row = $result->fetch_assoc()) {
$visitorId = $row['id'];
$name = $row['first_name'] . ' ' . $row['last_name'];
$checkInTime = $row['time_in'];
$checkOutTime = $row['time_out'];
$status = ($checkOutTime != null) ? 'Checked Out' : 'Checked In';

echo "Name: " . $name . "<br>";


echo "Check-in Time: " . $checkInTime . "<br>";
echo "Check-out Time: " . $checkOutTime . "<br>";
echo "Status: " . $status . "<br>";

// Display the form for filling out the checkout time


if ($status === 'Checked In') {
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?
>">
<input type="hidden" name="visitor-id" value="<?php echo
$visitorId; ?>">
<label for="time-out">Checkout Time:</label>
<input type="datetime-local" id="time-out" name="time-out">
<button type="submit">Fill Out Checkout</button>
</form>
<?php
}

echo "<br><br>";
}
} else {
echo "No visitor records found.";
}

// Close the database connection


$connection->close();
?>

</body>
</html>

Connection.php
<?php

$conn = "";

try {
$servername = "localhost:3306";
$dbname = "myapp";
$username = "root";
$password = "";

$conn = new PDO(


"mysql:host=$servername; dbname=myapp",
$username, $password
);

$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}

?>

Delete_user.php

<?php
// Retrieve the user ID from the query parameter
$userId = $_GET['id'];

// Replace the placeholder values with your actual database credentials


$host = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $dbUsername, $dbPassword, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Prepare the SQL statement to delete the user from the table
$sql = "DELETE FROM users WHERE id = $userId";

// Execute the SQL statement


if ($connection->query($sql) === TRUE) {
echo 'User deleted successfully';
} else {
echo 'Error: ' . $sql . '<br>' . $connection->error;
}

// Close the database connection


$connection->close();
?>

Masijala.php

<!DOCTYPE html>
<html>
<head>
<title>Welcome Page</title>
</head>
<body>
<h1>Welcome to Masijala</h1>

<?php
// Replace the placeholder values with your actual database credentials
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'myapp';

// Create a new MySQLi connection


$connection = new mysqli($host, $username, $password, $database);

// Check if the connection was successful


if ($connection->connect_error) {
die('Connection failed: ' . $connection->connect_error);
}

// Check if the form is submitted for filling out the checkout time
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$visitorId = $_POST['visitor-id'];
$timeOut = $_POST['time-out'];

// Prepare an SQL statement to update the checkout time for the visitor
$sql = "UPDATE visitors SET time_out = ? WHERE id = ?";
$stmt = $connection->prepare($sql);

// Bind the form data to the SQL statement


$stmt->bind_param("si", $timeOut, $visitorId);

// Execute the prepared statement


if ($stmt->execute()) {
echo "Checkout time updated successfully.";
} else {
// Handle the case where the statement execution fails
echo "Error updating checkout time: " . $stmt->error;
}

// Close the prepared statement


$stmt->close();
}

// Retrieve the visitor records from the database


$sql = "SELECT * FROM visitors";
$result = $connection->query($sql);

// Check if any visitor records exist


if ($result->num_rows > 0) {
// Output the visitor status and provide a form for filling out the
checkout time
while ($row = $result->fetch_assoc()) {
$visitorId = $row['id'];
$name = $row['first_name'] . ' ' . $row['last_name'];
$checkInTime = $row['time_in'];
$checkOutTime = $row['time_out'];
$status = ($checkOutTime != null) ? 'Checked Out' : 'Checked In';

echo "Name: " . $name . "<br>";


echo "Check-in Time: " . $checkInTime . "<br>";
echo "Check-out Time: " . $checkOutTime . "<br>";
echo "Status: " . $status . "<br>";

// Display the form for filling out the checkout time


if ($status === 'Checked In') {
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?
>">
<input type="hidden" name="visitor-id" value="<?php echo
$visitorId; ?>">
<label for="time-out">Checkout Time:</label>
<input type="datetime-local" id="time-out" name="time-out">
<button type="submit">Fill Out Checkout</button>
</form>
<?php
}

echo "<br><br>";
}
} else {
echo "No visitor records found.";
}

// Close the database connection


$connection->close();
?>

</body>
</html>

View.php

<?php
// Database connection details
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myapp";

// Get current date


$currentDate = date('Y-m-d');

// Create a new database connection


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

// Check if the connection was successful


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

// Prepare the SQL statement to retrieve visitor records for the current day
$sql = "SELECT * FROM visitor WHERE DATE(time_in) = '$currentDate'";

// Execute the SQL statement


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

// Check if there are any visitor records for the current day
if ($result->num_rows > 0) {
echo '<h2>Visitor Records for ' . $currentDate . '</h2>';
echo '<table>';
echo '<tr>';
echo '<th>First Name</th>';
echo '<th>Last Name</th>';
echo '<th>Phone Number</th>';
echo '<th>Office</th>';
echo '<th>Address</th>';
echo '<th>Time In</th>';
echo '<th>Time Out</th>';
echo '</tr>';

// Output data of each row


while ($row = $result->fetch_assoc()) {
echo '<tr>';
echo '<td>' . $row['first_name'] . '</td>';
echo '<td>' . $row['last_name'] . '</td>';
echo '<td>' . $row['phone_number'] . '</td>';
echo '<td>' . $row['office'] . '</td>';
echo '<td>' . $row['address'] . '</td>';
echo '<td>' . $row['time_in'] . '</td>';
echo '<td>' . $row['time_out'] . '</td>';
echo '</tr>';
}

echo '</table>';
} else {
echo 'No visitor records for ' . $currentDate;
}

// Close the database connection


$conn->close();
?>
Here is the correct database code to create a database that will work with the
Gate Management System:

**Create the database:**

```sql

CREATE DATABASE myapp;

```

**Create the users table:**

```sql

CREATE TABLE users (

id INT PRIMARY KEY AUTO_INCREMENT,

username VARCHAR(255) NOT NULL,

password VARCHAR(255) NOT NULL

);

```

**Create the visitors table:**

```sql

CREATE TABLE visitors (

id INT PRIMARY KEY AUTO_INCREMENT,

visitor_id INT,

first_name VARCHAR(255),

last_name VARCHAR(255),

office VARCHAR(255),

time_in DATETIME,
time_out DATETIME,

visitor_number INT,

FOREIGN KEY (visitor_id) REFERENCES users(id)

);

```

**Insert the database credentials into the PHP code:**

Replace the following lines in your PHP code:

```php

$host = 'localhost';

$dbUsername = 'root';

$dbPassword = '';

$database = 'myapp';

```

With:

```php

$host = 'localhost';

$dbUsername = 'root';

$dbPassword = '';

$database = 'myapp';

```

**Note:** Make sure to replace the placeholder values with your actual database
credentials.

**Also, ensure that the MySQLi extension is installed and enabled in your PHP
configuration.**

INSERT INTO users (username, password) VALUES ('user', 'user');


Ismail

Cart.php

<?php
session_start();
require 'connection.php';
if(!isset($_SESSION['email'])){
header('location: login.php');
}
$user_id=$_SESSION['id'];
$user_products_query="select it.id,it.name,it.price from users_items ut inner
join items it on it.id=ut.item_id where ut.user_id='$user_id'";
$user_products_result=mysqli_query($con,$user_products_query) or
die(mysqli_error($con));
$no_of_user_products= mysqli_num_rows($user_products_result);
$sum=0;
if($no_of_user_products==0){
//echo "Add items to cart first.";
?>
<script>
window.alert("No items in the cart!!");
</script>
<?php
}else{
while($row=mysqli_fetch_array($user_products_result)){
$sum=$sum+$row['price'];
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="img/lifestyleStore.png" />
<title>Lifestyle Store</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- latest compiled and minified CSS -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"
type="text/css">
<!-- jquery library -->
<script type="text/javascript" src="bootstrap/js/jquery-
3.2.1.min.js"></script>
<!-- Latest compiled and minified javascript -->
<script type="text/javascript"
src="bootstrap/js/bootstrap.min.js"></script>
<!-- External CSS -->
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div>
<?php
require 'header.php';
?>
<br>
<div class="container">
<table class="table table-bordered table-striped">
<tbody>
<tr>
<th>Item Number</th><th>Item
Name</th><th>Price</th><th></th>
</tr>
<?php
$user_products_result=mysqli_query($con,
$user_products_query) or die(mysqli_error($con));
$no_of_user_products=
mysqli_num_rows($user_products_result);
$counter=1;
while($row=mysqli_fetch_array($user_products_result)){

?>
<tr>
<th><?php echo $counter ?></th><th><?php echo
$row['name']?></th><th><?php echo $row['price']?></th>
<th><a href='cart_remove.php?id=<?php echo
$row['id'] ?>'>Remove</a></th>
</tr>
<?php $counter=$counter+1;}?>
<tr>
<th></th><th>Total</th><th>Rs <?php echo $sum;?>/-
</th><th><a href="success.php?id=<?php echo $user_id?>" class="btn btn-
primary">Confirm Order</a></th>
</tr>
</tbody>
</table>
</div>
<br><br><br><br><br><br><br><br><br><br>
<footer class="footer">
<div class="container">
<center>
<p>Copyright &copy Lifestyle Store. All Rights Reserved. |
Contact Us: +255 717999790</p>
<p>This website is developed by Lucas Samson</p>
</center>
</div>
</footer>
</div>
</body>
</html>

Connection.php

<?php
/
*$con=mysqli_connect("localhost","id2538044_sajalagrawal","******","id2538044_sto
re") or die(mysqli_error($con));*/
$con=mysqli_connect("localhost","root","","store") or die(mysqli_error($con));
?>

Hearder.php

<nav class="navbar navbar-inverse navabar-fixed-top">


<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-
toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.php" class="navbar-brand">Lifestyle
Store</a>
</div>

<div class="collapse navbar-collapse" id="myNavbar">


<ul class="nav navbar-nav navbar-right">
<?php
if(isset($_SESSION['email'])){
?>
<li><a href="cart.php"><span class="glyphicon
glyphicon-shopping-cart"></span> Cart</a></li>
<li><a href="settings.php"><span class="glyphicon
glyphicon-cog"></span> Settings</a></li>
<li><a href="logout.php"><span class="glyphicon
glyphicon-log-out"></span> Logout</a></li>
<?php
}else{
?>
<li><a href="signup.php"><span class="glyphicon
glyphicon-user"></span> Sign Up</a></li>
<li><a href="login.php"><span class="glyphicon
glyphicon-log-in"></span> Login</a></li>
<?php
}
?>

</ul>
</div>
</div>
</nav>

Comfirmation.php

<?php
session_start();
require 'connection.php';
if(!isset($_SESSION['email'])){
header('location:index.php');
}else{
$user_id=$_GET['id'];
$confirm_query="update users_items set status='Confirmed' where
user_id=$user_id";
$confirm_query_result=mysqli_query($con,$confirm_query) or
die(mysqli_error($con));

}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="img/lifestyleStore.png" />
<title>Lifestyle Store</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- latest compiled and minified CSS -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"
type="text/css">
<!-- jquery library -->
<script type="text/javascript" src="bootstrap/js/jquery-
3.2.1.min.js"></script>
<!-- Latest compiled and minified javascript -->
<script type="text/javascript"
src="bootstrap/js/bootstrap.min.js"></script>
<!-- External CSS -->
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div>
<?php
require 'header.php';
?>
<br>
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="panel panel-primary">
<div class="panel-heading"></div>
<div class="panel-body">
<p>Your order is confirmed. Thank you for
shopping with us. <a href="products.php">Click here</a> to purchase any other
item.</p>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<center>
<p>Copyright &copy Lifestyle Store. All Rights Reserved. |
Contact Us: +255 717999790</p>
<p>This website is developed by Lucus Samson</p>
</center>
</div>
</footer>
</div>
</body>
</html>
Products.php

<?php
session_start();
require 'check_if_added.php';
?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="img/lifestyleStore.png" />
<title>Lifestyle Store</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- latest compiled and minified CSS -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"
type="text/css">
<!-- jquery library -->
<script type="text/javascript" src="bootstrap/js/jquery-
3.2.1.min.js"></script>
<!-- Latest compiled and minified javascript -->
<script type="text/javascript"
src="bootstrap/js/bootstrap.min.js"></script>
<!-- External CSS -->
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div>
<?php
require 'header.php';
?>
<div class="container">
<div class="jumbotron">
<h1>Welcome to our LifeStyle Store!</h1>
<p>We have the best suit, Trousers and shirts for you. No
need to hunt around, we have all in one place.</p>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/shirt.jpg" alt="Cannon">
</a>
<center>
<div class="caption">
<h3>Cannon EOS</h3>
<p>Price: Tsh. 36000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(1)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=1"
class="btn btn-block btn-primary" name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>

</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/pink.jpg" alt="Sony DSLR">
</a>
<center>
<div class="caption">
<h3>Sony DSLR</h3>
<p>Price: Tsh. 40000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(2)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=2"
class="btn btn-block btn-primary" name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/HXR.jpg" alt="Sony DSLR">
</a>
<center>
<div class="caption">
<h3>Sony DSLR</h3>
<p>Price: Tsh. 50000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(3)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=3"
class="btn btn-block btn-primary" name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/hmt.jpg" alt="Olympus">
</a>
<center>
<div class="caption">
<h3>Olympus DSLR</h3>
<p>Price: Tsh. 80000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(4)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=4"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/shirt.jpg" alt="Titan 301">
</a>
<center>
<div class="caption">
<h3>Titan Model #301</h3>
<p>Price: Tsh. 130000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(5)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=5"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/sony_dslr.jpg" alt="Titan 201">
</a>
<center>
<div class="caption">
<h3>Titan Model #201</h3>
<p>Price: Tsh. 30000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(6)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=6"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/sony_dslr2.JPG" alt="htm milan">
</a>
<center>
<div class="caption">
<h3>HMT Milan</h3>
<p>Price: Tsh. 80000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(7)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=7"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/raymond.jpg" alt="Favre Leuba">
</a>
<center>
<div class="caption">
<h3>Favre Leuba #111</h3>
<p>Price: Tsh. 18000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(8)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=8"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
</div>
<div class="row">
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/shirt.jpg" alt="Raymond shirt">
</a>
<center>
<div class="caption">
<h3>Raymond</h3>
<p>Price: Tsh. 50000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(9)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=9"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/charles.jpg" alt="Charles shirt">
</a>
<center>
<div class="caption">
<h3>Charles</h3>
<p>Price: Tsh. 10000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(10)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=10"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/HXR.jpg" alt="HXR">
</a>
<center>
<div class="caption">
<h3>HXR</h3>
<p>Price: Tsh. 90000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(11)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=11"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<a href="cart.php">
<img src="img/pink.jpg" alt="PINK">
</a>
<center>
<div class="caption">
<h3>PINK</h3>
<p>Price: Tsh. 25000.00</p>
<?php if(!isset($_SESSION['email'])){ ?>
<p><a href="login.php" role="button"
class="btn btn-primary btn-block">Buy Now</a></p>
<?php
}
else{
if(check_if_added_to_cart(12)){
echo '<a href="#" class=btn btn-
block btn-success disabled>Added to cart</a>';
}else{
?>
<a href="cart_add.php?id=12"
class="btn btn-block btn-primary " name="add" value="add" class="btn btn-block
btr-primary">Add to cart</a>
<?php
}
}
?>
</div>
</center>
</div>
</div>
</div>
</div>
<br><br><br><br><br><br><br><br>
<footer class="footer">
<div class="container">
<center>
<p>Copyright &copy Lifestyle Store. All Rights Reserved. |
Contact Us: +255 717999790</p>
<p>This website is developed by Lucas Samson</p>
</center>
</div>
</footer>
</div>
</body>
</html>

Cart_add.php

<?php
require 'connection.php';
//require 'header.php';
session_start();
$item_id=$_GET['id'];
$user_id=$_SESSION['id'];
$add_to_cart_query="insert into users_items(user_id,item_id,status) values
('$user_id','$item_id','Added to cart')";
$add_to_cart_result=mysqli_query($con,$add_to_cart_query) or
die(mysqli_error($con));
header('location: products.php');
?>

You might also like