Project Report: On Online Voting Management System Submitted To Dept. of Computer, LNMI
Project Report: On Online Voting Management System Submitted To Dept. of Computer, LNMI
Project Report: On Online Voting Management System Submitted To Dept. of Computer, LNMI
CHAPTER - 2
o Programming Languages Used
PHP
HTML
CSS
JavaScript
MySQL (Database)
CHAPTER – 3
o What is DFD?
o DFD Notations
o Levels of DFD
o Information Sharing and Complaint Registration
Website DFD
CHAPTER – 4
o Entity-Relationship Diagram
o Gantt Chart
CHAPTER – 5
o Planning
o Analysis
o Design and Development
o Testing
o Implementation
o Maintenance
CHAPTER – 6
CHAPTER – 7
CHAPTER - 8
o Conclusion
o References and Bibliography
CHAPTER - 1
Votes:
The Votes page displays all the votes given by the voters to
the respective candidates. It makes the voting process
transparent and accountable.
Voters Page:
The Voters page allows the admin to modify the voters'
details, such as name.This helps to keep the voter database
up-to-date and accurate.
Position and Candidates Page:
The Position and Candidates pages allow the admin to modify
all the necessary details related to the candidates, such as
their name, position, and photo. The admin can also modify
the ballot position and title of the voting page, making it
more customizable and flexible.
User Interface
On the user side, our website offers a user-friendly interface
that allows the voter to cast their vote and preview their
choices before submitting them. This helps to eliminate
errors and ensures that the voting process is smooth and
efficient.
5. Database support
PHP provides support for various databases such as MySQL,
Oracle, and PostgreSQL.
6. Security
PHP provides various built-in functions for security, such as
protection against SQL injection attacks.
7. Large community
PHP has a large community of developers who contribute to
its development and provide support through forums and
user groups.
Overall, PHP is a powerful and flexible language that is widely
used in web development.
HTML
HTML (Hypertext Markup Language) is a markup language is
most widely used language on Web to develop web pages.
Here are some key features of HTML:
1. Structure
HTML provides a structure for web pages, allowing
developers to create headings, paragraphs, lists, and other
elements.
2. Tags
HTML uses tags to indicate the beginning and end of
elements on a web page. For example, the <p> tag is used to
indicate the beginning of a paragraph.
3. Attributes
HTML tags can also have attributes, which provide additional
information about an element. For example, the <img> tag
has an attribute called src, which indicates the URL of the
image to be displayed.
4. Accessibility
HTML provides features for making web pages accessible to
users with disabilities, such as using alternative text for
images and providing captions for videos.
5. Compatibility
HTML is supported by all modern web browsers and can be
used with other web technologies such as CSS and JavaScript.
JavaScript
JavaScript is a programming language used to create
interactive and dynamic web pages. Here are some key
features of JavaScript:
1. Interaction
JavaScript is used to add interactivity to web pages, such as
responding to user events like clicks or keypresses.
2. Variables and data types
JavaScript supports variables, which can hold different types
of data, such as numbers, strings, and booleans.
3. Control flow
JavaScript supports control flow statements, such as if-else
statements and loops, to control the order in which code is
executed.
4. Functions
JavaScript supports functions, which are reusable blocks of
code that can be called multiple times.
5. Compatibility
JavaScript is supported by all modern web browsers and can
be used with other web technologies such as HTML and CSS.
Hardware:
Component Specification
Processor Ryzen-5
RAM 8 GB
SSD 512 GB
CHAPTER – 3
o What is DFD?
o DFD Notations
o Levels of DFD
o Information Sharing and Complaint Registration
Website DFD
What is DFD?
1-level DFD:
In 1-level DFD, the context diagram is decomposed into
multiple bubbles/processes. In this level, we highlight the
main functions of the system and breakdown the high-level
process of 0-level DFD into subprocesses.
2-level DFD:
2-level DFD goes one step deeper into parts of 1-level DFD.
It can be used to plan or record the specific/necessary detail
about the system’s functioning.
CHAPTER – 4
o Entity-Relationship Diagram
o Gantt Chart
Er Diagram
CHAPTER – 5
Design: In the design stage, you will create a design for the
online voting system. You will develop a user interface
design, database schema, and system architecture. You will
also create wireframes and prototypes to help stakeholders
visualize the final product.
Maintenance
Maintaining a website is essential to keep it up-to-date,
improve user experience, and ensure that it remains relevant
to its audience. Here are some steps involved in maintaining
such a website:
1. Regularly update content
Regularly update the website with new audio content to
keep it fresh and relevant. This can include interviews, news
updates, and educational materials.
2. Monitor website performance
Use website analytics tools to monitor website traffic, user
engagement, and conversion rates. This will help you identify
areas for improvement and make data-driven decisions to
improve the website's performance.
3. Optimize website for SEO
Continuously optimize the website for search engines by
updating keywords, meta tags, and descriptions. This will
improve the website's visibility and increase organic traffic.
4. Test website functionality
Test the website's functionality regularly to ensure that all
features are working correctly. This can include audio player,
search function, and other interactive features.
5. Check for broken links
Check for broken links on the website and fix them promptly
to improve user experience and prevent negative SEO
impact.
<div class="col-sm-9">
<input type="text" class="form-control"
id="firstname" name="firstname" required>
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-3
control-label">Lastname</label>
<div class="col-sm-9">
<input type="text" class="form-control"
id="lastname" name="lastname" required>
</div>
</div>
<div class="form-group">
<label for="position" class="col-sm-3 control-
label">Position</label>
<div class="col-sm-9">
<select class="form-control" id="position"
name="position" required>
<option value="" selected>- Select
-</option>
<?php
$sql = "SELECT * FROM positions";
$query = $conn->query($sql);
while($row = $query->fetch_assoc()){
echo "
<option value='".$row['id']."'>".
$row['description']."</option>
";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="photo" class="col-sm-3 control-
label">Photo</label>
<div class="col-sm-9">
<input type="file" id="photo"
name="photo">
</div>
</div>
<div class="form-group">
<label for="platform" class="col-sm-3
control-label">Platform</label>
<div class="col-sm-9">
<textarea class="form-control"
id="platform" name="platform" rows="7"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-primary
btn-flat" name="add"><i class="fa fa-save"></i>
Save</button>
</form>
</div>
</div>
</div>
</div>
<div class="col-sm-9">
<input type="text" class="form-control"
id="edit_firstname" name="firstname" required>
</div>
</div>
<div class="form-group">
<label for="edit_lastname" class="col-sm-3
control-label">Lastname</label>
<div class="col-sm-9">
<input type="text" class="form-control"
id="edit_lastname" name="lastname" required>
</div>
</div>
<div class="form-group">
<label for="edit_position" class="col-sm-3
control-label">Position</label>
<div class="col-sm-9">
<select class="form-control"
id="edit_position" name="position" required>
<option value="" selected
id="posselect"></option>
<?php
$sql = "SELECT * FROM positions";
$query = $conn->query($sql);
while($row = $query->fetch_assoc()){
echo "
<option value='".$row['id']."'>".
$row['description']."</option>
";
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="edit_platform" class="col-sm-3
control-label">Platform</label>
<div class="col-sm-9">
<textarea class="form-control"
id="edit_platform" name="platform"
rows="7"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-success
btn-flat" name="edit"><i class="fa fa-check-square-
o"></i> Update</button>
</form>
</div>
</div>
</div>
</div>
<div class="col-sm-9">
<input type="file" id="photo"
name="photo" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-success
btn-flat" name="upload"><i class="fa fa-check-square-
o"></i> Update</button>
</form>
</div>
</div>
</div>
</div>
config_modal.php
<div class="col-sm-9">
<input type="text" class="form-control"
id="title" name="title" value="<?php echo $title; ?>">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-success
btn-flat" name="save"><i class="fa fa-save"></i>
Save</button>
</form>
</div>
</div>
</div>
</div>
conn.php
<?php
$conn = new mysqli('localhost', 'root', '',
'votesystem');
if ($conn->connect_error) {
die("Connection failed: " . $conn-
>connect_error);
}
?>
footer.php
<footer class="main-footer">
<div class="pull-right hidden-xs">
</div>
<strong>ONLINE VOTING MANAGMENT SYSTEM</strong>
</footer>
header.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<title>Voting System using PHP</title>
<!-- Tell the browser to be responsive to screen width --
>
<meta content="width=device-width, initial-scale=1,
maximum-scale=1, user-scalable=no" name="viewport">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet"
href="../bower_components/bootstrap/dist/css/bootstrap.m
in.css">
<!-- iCheck for checkboxes and radio inputs -->
<link rel="stylesheet" href="../plugins/iCheck/all.css">
<!-- Font Awesome -->
<link rel="stylesheet" href="../bower_components/font-
awesome/css/font-awesome.min.css">
<!-- Theme style -->
<link rel="stylesheet"
href="../dist/css/AdminLTE.min.css">
<!-- DataTables -->
<link rel="stylesheet"
href="../bower_components/datatables.net-bs/css/dataTabl
es.bootstrap.min.css">
<!-- daterange picker -->
<link rel="stylesheet"
href="../bower_components/bootstrap-daterangepicker/dat
erangepicker.css">
<!-- Bootstrap time Picker -->
<link rel="stylesheet"
href="../plugins/timepicker/bootstrap-timepicker.min.css">
<!-- bootstrap datepicker -->
<link rel="stylesheet"
href="../bower_components/bootstrap-datepicker/dist/css/b
ootstrap-datepicker.min.css">
<!-- AdminLTE Skins. Choose a skin from the css/skins
folder instead of downloading all of them to reduce the
load. -->
<link rel="stylesheet" href="../dist/css/skins/_all-
skins.min.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5
elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the
page via file:// -->
<!--[if lt IE 9]>
<script
src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min
.js"></script>
<script
src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"
></script>
<![endif]-->
<style type="text/css">
.bold{
font-weight:bold;
}
#candidate_list{
margin-top:20px;
}
#candidate_list ul{
list-style-type:none;
}
#candidate_list ul li{
margin:0 30px 30px 0;
vertical-align:top
}
.clist{
margin-left: 20px;
}
.cname{
font-size: 25px;
}
</style>
</head>
menubar.php
<aside class="main-sidebar">
<!-- sidebar: style can be found in sidebar.less -->
<section class="sidebar">
<!-- Sidebar user panel -->
<div class="user-panel">
<div class="pull-left image">
<img src="<?php echo (!empty($user['photo'])) ?
'../images/'.$user['photo'] : '../images/profile.jpg'; ?>"
class="img-circle" alt="User Image">
</div>
<div class="pull-left info">
<p><?php echo $user['firstname'].' '.
$user['lastname']; ?></p>
<a><i class="fa fa-circle text-success"></i>
Online</a>
</div>
</div>
<!-- sidebar menu: : style can be found in sidebar.less
-->
<ul class="sidebar-menu" data-widget="tree">
<li class="header">REPORTS</li>
<li class=""><a href="home.php"><i class="fa fa-
dashboard"></i> <span>Dashboard</span></a></li>
<li class=""><a href="votes.php"><span
class="glyphicon glyphicon-lock"></span>
<span>Votes</span></a></li>
<li class="header">MANAGE</li>
<li class=""><a href="voters.php"><i class="fa fa-
users"></i> <span>Voters</span></a></li>
<li class=""><a href="positions.php"><i class="fa fa-
tasks"></i> <span>Positions</span></a></li>
<li class=""><a href="candidates.php"><i class="fa fa-
black-tie"></i> <span>Candidates</span></a></li>
<li class="header">SETTINGS</li>
<li class=""><a href="ballot.php"><i class="fa fa-file-
text"></i> <span>Ballot Position</span></a></li>
<li class=""><a href="#config" data-
toggle="modal"><i class="fa fa-cog"></i>
<span>Election Title</span></a></li>
</ul>
</section>
<!-- /.sidebar -->
</aside>
<?php include 'config_modal.php'; ?>
navbar.php
<header class="main-header">
<!-- Logo -->
<a href="#" class="logo">
<!-- mini logo for sidebar mini 50x50 pixels -->
<span class="logo-mini"><b>V</b>TS</span>
<!-- logo for regular state and mobile devices -->
<span class="logo-lg"><b>Voting</b>System</span>
</a>
<!-- Header Navbar: style can be found in header.less --
>
<nav class="navbar navbar-static-top">
<!-- Sidebar toggle button-->
<a href="#" class="sidebar-toggle" data-toggle="push-
menu" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- User Account: style can be found in
dropdown.less -->
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-
toggle="dropdown">
<img src="<?php echo (!empty($user['photo'])) ?
'../images/'.$user['photo'] : '../images/profile.jpg'; ?>"
class="user-image" alt="User Image">
<span class="hidden-xs"><?php echo
$user['firstname'].' '.$user['lastname']; ?></span>
</a>
<ul class="dropdown-menu">
<!-- User image -->
<li class="user-header">
<img src="<?php echo (!empty($user['photo'])) ?
'../images/'.$user['photo'] : '../images/profile.jpg'; ?>"
class="img-circle" alt="User Image">
<p>
<?php echo $user['firstname'].' '.
$user['lastname']; ?></br>
<small>ADMIN</small>
</p>
</li>
<li class="user-footer">
<div class="pull-left">
<a href="#profile" data-toggle="modal"
class="btn btn-default btn-flat"
id="admin_profile">Update</a>
</div>
<div class="pull-right">
<a href="logout.php" class="btn btn-default
btn-flat">Sign out</a>
</div>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</header>
<?php include 'includes/profile_modal.php'; ?>
positions_modal.php
<div class="col-sm-9">
<input type="text" class="form-control"
id="description" name="description" required>
</div>
</div>
<div class="form-group">
<label for="max_vote" class="col-sm-3
control-label">Maximum Vote</label>
<div class="col-sm-9">
<input type="number" class="form-control"
id="max_vote" name="max_vote" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-primary
btn-flat" name="add"><i class="fa fa-save"></i>
Save</button>
</form>
</div>
</div>
</div>
</div>
<div class="col-sm-9">
<input type="text" class="form-control"
id="edit_description" name="description">
</div>
</div>
<div class="form-group">
<label for="edit_max_vote" class="col-sm-3
control-label">Maximum Vote</label>
<div class="col-sm-9">
<input type="number" class="form-control"
id="edit_max_vote" name="max_vote">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-success
btn-flat" name="edit"><i class="fa fa-check-square-
o"></i> Update</button>
</form>
</div>
</div>
</div>
</div>
profile_modal.php
<div class="col-sm-9">
<input type="text" class="form-control"
id="username" name="username" value="<?php echo
$user['username']; ?>">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3
control-label">Password</label>
<div class="col-sm-9">
<input type="password" class="form-
control" id="password" name="password" value="<?
php echo $user['password']; ?>">
</div>
</div>
<div class="form-group">
<label for="firstname" class="col-sm-3
control-label">Firstname</label>
<div class="col-sm-9">
<input type="text" class="form-control"
id="firstname" name="firstname" value="<?php echo
$user['firstname']; ?>">
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-3
control-label">Lastname</label>
<div class="col-sm-9">
<input type="text" class="form-control"
id="lastname" name="lastname" value="<?php echo
$user['lastname']; ?>">
</div>
</div>
<div class="form-group">
<label for="photo" class="col-sm-3 control-
label">Photo:</label>
<div class="col-sm-9">
<input type="file" id="photo"
name="photo">
</div>
</div>
<hr>
<div class="form-group">
<label for="curr_password" class="col-sm-3
control-label">Current Password:</label>
<div class="col-sm-9">
<input type="password" class="form-
control" id="curr_password" name="curr_password"
placeholder="input current password to save changes"
required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-success
btn-flat" name="save"><i class="fa fa-check-square-
o"></i> Save</button>
</form>
</div>
</div>
</div>
</div>
scripts.php
// for treeview
$('ul.treeview-menu a').filter(function() {
return this.href == url;
}).parentsUntil(".sidebar-menu > .treeview-
menu").addClass('active');
});
</script>
<!-- Data Table Initialize -->
<script>
$(function () {
$('#example1').DataTable()
$('#example2').DataTable({
'paging' : true,
'lengthChange': false,
'searching' : false,
'ordering' : true,
'info' : true,
'autoWidth' : false
})
})
</script>
<!-- Date and Timepicker -->
<script>
$(function(){
//Date picker
$('#datepicker_add').datepicker({
autoclose: true,
format: 'yyyy-mm-dd'
})
$('#datepicker_edit').datepicker({
autoclose: true,
format: 'yyyy-mm-dd'
})
});
</script>
session.php
<?php
session_start();
include 'includes/conn.php';
if(!isset($_SESSION['admin']) ||
trim($_SESSION['admin']) == ''){
header('location: index.php');
}
?>
slugify.php
<?php
function slugify($string){
$preps = array('in', 'at', 'on', 'by', 'into', 'off', 'onto',
'from', 'to', 'with', 'a', 'an', 'the', 'using', 'for');
$pattern = '/\b(?:' . join('|', $preps) . ')\b/i';
$string = preg_replace($pattern, '', $string);
$string = preg_replace('~[^\\pL\d]+~u', '-', $string);
$string = trim($string, '-');
$string = iconv('utf-8', 'us-ascii//TRANSLIT', $string);
$string = strtolower($string);
$string = preg_replace('~[^-\w]+~', '', $string);
return $string;
?>
voters_modal.php
<div class="col-sm-9">
<input type="text" class="form-control"
id="firstname" name="firstname" required>
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-3
control-label">Lastname</label>
<div class="col-sm-9">
<input type="text" class="form-control"
id="lastname" name="lastname" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3
control-label">Password</label>
<div class="col-sm-9">
<input type="password" class="form-
control" id="password" name="password" required>
</div>
</div>
<div class="form-group">
<label for="photo" class="col-sm-3 control-
label">Photo</label>
<div class="col-sm-9">
<input type="file" id="photo"
name="photo">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-primary
btn-flat" name="add"><i class="fa fa-save"></i>
Save</button>
</form>
</div>
</div>
</div>
</div>
<div class="col-sm-9">
<input type="text" class="form-control"
id="edit_firstname" name="firstname">
</div>
</div>
<div class="form-group">
<label for="edit_lastname" class="col-sm-3
control-label">Lastname</label>
<div class="col-sm-9">
<input type="text" class="form-control"
id="edit_lastname" name="lastname">
</div>
</div>
<div class="form-group">
<label for="edit_password" class="col-sm-3
control-label">Password</label>
<div class="col-sm-9">
<input type="password" class="form-
control" id="edit_password" name="password">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-success
btn-flat" name="edit"><i class="fa fa-check-square-
o"></i> Update</button>
</form>
</div>
</div>
</div>
</div>
<div class="col-sm-9">
<input type="file" id="photo"
name="photo" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default
btn-flat pull-left" data-dismiss="modal"><i class="fa fa-
close"></i> Close</button>
<button type="submit" class="btn btn-success
btn-flat" name="upload"><i class="fa fa-check-square-
o"></i> Update</button>
</form>
</div>
</div>
</div>
</div>
votes_modal.php
ballot.php
<div class="row">
<div class="col-xs-10 col-xs-offset-1" id="content">
</div>
</div>
</section>
</div>
});
function fetch(){
$.ajax({
type: 'POST',
url: 'ballot_fetch.php',
dataType: 'json',
success: function(response){
$('#content').html(response).iCheck({checkboxClass:
'icheckbox_flat-green',radioClass: 'iradio_flat-green'});
}
});
}
</script>
</body>
</html>
ballot_down.php
<?php
include 'includes/session.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$sql = "SELECT * FROM positions";
$pquery = $conn->query($sql);
$output = array('error'=>false);
$priority = $row['priority'] + 1;
echo json_encode($output);
}
?>
ballot_fetch.php
<?php
include 'includes/session.php';
include 'includes/slugify.php';
$output = '';
$candidate = '';
$output .= '
<div class="row">
<div class="col-xs-12">
<div class="box box-solid" id="'.
$row['id'].'">
<div class="box-header
with-border">
<h3 class="box-
title"><b>'.$row['description'].'</b></h3>
<div class="pull-right
box-tools">
<button type="button"
class="btn btn-default btn-sm moveup" data-id="'.
$row['id'].'" '.$updisable.'><i class="fa fa-arrow-up"></i>
</button>
<button type="button"
class="btn btn-default btn-sm movedown" data-id="'.
$row['id'].'" '.$downdisable.'><i class="fa fa-arrow-
down"></i></button>
</div>
</div>
<div class="box-body">
<p>'.$instruct.'
<span
class="pull-right">
<button
type="button" class="btn btn-success btn-sm btn-flat
reset" data-desc="'.slugify($row['description']).'"><i
class="fa fa-refresh"></i> Reset</button>
</span>
</p>
<div
id="candidate_list">
<ul>
'.
$candidate.'
</ul>
</div>
</div>
</div>
</div>
</div>
';
$num++;
$candidate = '';
}
echo json_encode($output);
?>
ballot_up.php
<?php
include 'includes/session.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$output = array('error'=>false);
$priority = $row['priority'] - 1;
if($priority == 0){
$output['error'] = true;
$output['message'] = 'This position is
already at the top';
}
else{
$sql = "UPDATE positions SET priority =
priority + 1 WHERE priority = '$priority'";
$conn->query($sql);
echo json_encode($output);
?>
candidates.php
});
function getRow(id){
$.ajax({
type: 'POST',
url: 'candidates_row.php',
data: {id:id},
dataType: 'json',
success: function(response){
$('.id').val(response.canid);
$('#edit_firstname').val(response.firstname);
$('#edit_lastname').val(response.lastname);
$
('#posselect').val(response.position_id).html(response.d
escription);
$('#edit_platform').val(response.platform);
$('.fullname').html(response.firstname+'
'+response.lastname);
$('#desc').html(response.platform);
}
});
}
</script>
</body>
</html>
candidates_add.php
<?php
include 'includes/session.php';
if(isset($_POST['add'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$position = $_POST['position'];
$platform = $_POST['platform'];
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
move_uploaded_file($_FILES['photo']
['tmp_name'], '../images/'.$filename);
}
}
else{
$_SESSION['error'] = 'Fill up add form first';
}
header('location: candidates.php');
?>
candidates_delete.php
<?php
include 'includes/session.php';
if(isset($_POST['delete'])){
$id = $_POST['id'];
$sql = "DELETE FROM candidates WHERE id =
'$id'";
if($conn->query($sql)){
$_SESSION['success'] = 'Candidate
deleted successfully';
}
else{
$_SESSION['error'] = $conn->error;
}
}
else{
$_SESSION['error'] = 'Select item to delete
first';
}
header('location: candidates.php');
?>
candidates_edit.php
<?php
include 'includes/session.php';
if(isset($_POST['edit'])){
$id = $_POST['id'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$position = $_POST['position'];
$platform = $_POST['platform'];
header('location: candidates.php');
?>
candidates_photo.php
<?php
include 'includes/session.php';
if(isset($_POST['upload'])){
$id = $_POST['id'];
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
move_uploaded_file($_FILES['photo']
['tmp_name'], '../images/'.$filename);
}
}
else{
$_SESSION['error'] = 'Select candidate to
update photo first';
}
header('location: candidates.php');
?>
candidates_row.php
<?php
include 'includes/session.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$sql = "SELECT *, candidates.id AS canid FROM
candidates LEFT JOIN positions ON
positions.id=candidates.position_id WHERE
candidates.id = '$id'";
$query = $conn->query($sql);
$row = $query->fetch_assoc();
echo json_encode($row);
}
?>
config_save.php
<?php
include 'includes/session.php';
$return = 'home.php';
if(isset($_GET['return'])){
$return = $_GET['return'];
}
if(isset($_POST['save'])){
$title = $_POST['title'];
$file = 'config.ini';
$content = 'election_title = '.$title;
file_put_contents($file, $content);
}
else{
$_SESSION['error'] = "Fill up config form first";
}
header('location: '.$return);
?>
home.php
<?php include 'includes/session.php'; ?>
<?php include 'includes/slugify.php'; ?>
<?php include 'includes/header.php'; ?>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
echo "<h3>".$query->num_rows."</h3>";
?>
<p>No. of Positions</p>
</div>
<div class="icon">
<i class="fa fa-tasks"></i>
</div>
<a href="positions.php" class="small-box-
footer">More info <i class="fa
fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<?php
$sql = "SELECT * FROM candidates";
$query = $conn->query($sql);
echo "<h3>".$query->num_rows."</h3>";
?>
<p>No. of Candidates</p>
</div>
<div class="icon">
<i class="fa fa-black-tie"></i>
</div>
<a href="candidates.php" class="small-box-
footer">More info <i class="fa
fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<?php
$sql = "SELECT * FROM voters";
$query = $conn->query($sql);
echo "<h3>".$query->num_rows."</h3>";
?>
<p>Total Voters</p>
</div>
<div class="icon">
<i class="fa fa-users"></i>
</div>
<a href="voters.php" class="small-box-
footer">More info <i class="fa
fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<?php
$sql = "SELECT * FROM votes GROUP BY
voters_id";
$query = $conn->query($sql);
echo "<h3>".$query->num_rows."</h3>";
?>
<p>Voters Voted</p>
</div>
<div class="icon">
<i class="fa fa-edit"></i>
</div>
<a href="votes.php" class="small-box-
footer">More info <i class="fa
fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
</div>
<div class="row">
<div class="col-xs-12">
<h3>Votes Tally
</h3>
</div>
</div>
<?php
$sql = "SELECT * FROM positions ORDER BY priority
ASC";
$query = $conn->query($sql);
$inc = 2;
while($row = $query->fetch_assoc()){
$inc = ($inc == 2) ? 1 : $inc+1;
if($inc == 1) echo "<div class='row'>";
echo "
<div class='col-sm-6'>
<div class='box box-solid'>
<div class='box-header with-border'>
<h4 class='box-title'><b>".
$row['description']."</b></h4>
</div>
<div class='box-body'>
<div class='chart'>
<canvas id='".slugify($row['description'])."'
style='height:200px'></canvas>
</div>
</div>
</div>
</div>
";
if($inc == 2) echo "</div>";
}
if($inc == 1) echo "<div
class='col-sm-6'></div></div>";
?>
</section>
<!-- right col -->
</div>
<?php include 'includes/footer.php'; ?>
</div>
<!-- ./wrapper -->
barChartOptions.datasetFill = false
var myChart = barChart.HorizontalBar(barChartData,
barChartOptions)
//document.getElementById('legend_'+rowid).innerHT
ML = myChart.generateLegend();
});
</script>
<?php
}
?>
</body>
</html>
index.php
<?php
session_start();
if(isset($_SESSION['admin'])){
header('location:home.php');
}
?>
<?php include 'includes/header.php'; ?>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<b>Voting System</b>
</div>
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your
session</p>
login.php
<?php
session_start();
include 'includes/conn.php';
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
}
else{
$_SESSION['error'] = 'Input admin credentials
first';
}
header('location: index.php');
?>
logout.php
<?php
session_start();
session_destroy();
header('location: /votesystem/index.php');
?>
positions.php
});
function getRow(id){
$.ajax({
type: 'POST',
url: 'positions_row.php',
data: {id:id},
dataType: 'json',
success: function(response){
$('.id').val(response.id);
$('#edit_description').val(response.description);
$('#edit_max_vote').val(response.max_vote);
$('.description').html(response.description);
}
});
}
</script>
</body>
</html>
positions_add.php
<?php
include 'includes/session.php';
if(isset($_POST['add'])){
$description = $_POST['description'];
$max_vote = $_POST['max_vote'];
$priority = $row['priority'] + 1;
}
else{
$_SESSION['error'] = 'Fill up add form first';
}
header('location: positions.php');
?>
position_delete.php
<?php
include 'includes/session.php';
if(isset($_POST['delete'])){
$id = $_POST['id'];
$sql = "DELETE FROM positions WHERE id =
'$id'";
if($conn->query($sql)){
$_SESSION['success'] = 'Position deleted
successfully';
}
else{
$_SESSION['error'] = $conn->error;
}
}
else{
$_SESSION['error'] = 'Select item to delete
first';
}
header('location: positions.php');
?>
position_edit.php
<?php
include 'includes/session.php';
if(isset($_POST['edit'])){
$id = $_POST['id'];
$description = $_POST['description'];
$max_vote = $_POST['max_vote'];
header('location: positions.php');
?>
position_row.php
<?php
include 'includes/session.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$sql = "SELECT * FROM positions WHERE id =
'$id'";
$query = $conn->query($sql);
$row = $query->fetch_assoc();
echo json_encode($row);
}
?>
profile_update.php
<?php
include 'includes/session.php';
if(isset($_GET['return'])){
$return = $_GET['return'];
}
else{
$return = 'home.php';
}
if(isset($_POST['save'])){
$curr_password = $_POST['curr_password'];
$username = $_POST['username'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$photo = $_FILES['photo']['name'];
if(password_verify($curr_password,
$user['password'])){
if(!empty($photo)){
move_uploaded_file($_FILES['photo']['tmp_name'],
'../images/'.$photo);
$filename = $photo;
}
else{
$filename = $user['photo'];
}
if($password == $user['password']){
$password = $user['password'];
}
else{
$password =
password_hash($password, PASSWORD_DEFAULT);
}
}
else{
$_SESSION['error'] = 'Incorrect password';
}
}
else{
$_SESSION['error'] = 'Fill up required details
first';
}
header('location:'.$return);
?>
voters.php
});
function getRow(id){
$.ajax({
type: 'POST',
url: 'voters_row.php',
data: {id:id},
dataType: 'json',
success: function(response){
$('.id').val(response.id);
$('#edit_firstname').val(response.firstname);
$('#edit_lastname').val(response.lastname);
$('#edit_password').val(response.password);
$('.fullname').html(response.firstname+'
'+response.lastname);
}
});
}
</script>
</body>
</html>
voters_add.php
<?php
include 'includes/session.php';
if(isset($_POST['add'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password =
password_hash($_POST['password'],
PASSWORD_DEFAULT);
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
move_uploaded_file($_FILES['photo']
['tmp_name'], '../images/'.$filename);
}
//generate voters id
$set =
'123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL
MNOPQRSTUVWXYZ';
$voter = substr(str_shuffle($set), 0, 15);
header('location: voters.php');
?>
voters_delete.php
<?php
include 'includes/session.php';
if(isset($_POST['delete'])){
$id = $_POST['id'];
$sql = "DELETE FROM voters WHERE id =
'$id'";
if($conn->query($sql)){
$_SESSION['success'] = 'Voter deleted
successfully';
}
else{
$_SESSION['error'] = $conn->error;
}
}
else{
$_SESSION['error'] = 'Select item to delete
first';
}
header('location: voters.php');
?>
voters_edit.php
<?php
include 'includes/session.php';
if(isset($_POST['edit'])){
$id = $_POST['id'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$password = $_POST['password'];
if($password == $row['password']){
$password = $row['password'];
}
else{
$password = password_hash($password,
PASSWORD_DEFAULT);
}
$sql = "UPDATE voters SET firstname =
'$firstname', lastname = '$lastname', password =
'$password' WHERE id = '$id'";
if($conn->query($sql)){
$_SESSION['success'] = 'Voter updated
successfully';
}
else{
$_SESSION['error'] = $conn->error;
}
}
else{
$_SESSION['error'] = 'Fill up edit form first';
}
header('location: voters.php');
?>
voters_photo.php
<?php
include 'includes/session.php';
if(isset($_POST['upload'])){
$id = $_POST['id'];
$filename = $_FILES['photo']['name'];
if(!empty($filename)){
move_uploaded_file($_FILES['photo']
['tmp_name'], '../images/'.$filename);
}
}
else{
$_SESSION['error'] = 'Select voter to update
photo first';
}
header('location: voters.php');
?>
voters_row.php
<?php
include 'includes/session.php';
if(isset($_POST['id'])){
$id = $_POST['id'];
$sql = "SELECT * FROM voters WHERE id
= '$id'";
$query = $conn->query($sql);
$row = $query->fetch_assoc();
echo json_encode($row);
}
?>
votes.php
<?php
include 'includes/session.php';
header('location: votes.php');
?>
votesystem.sql
/*!40101 SET
@OLD_CHARACTER_SET_CLIENT=@@CHARACTER_
SET_CLIENT */;
/*!40101 SET
@OLD_CHARACTER_SET_RESULTS=@@CHARACTE
R_SET_RESULTS */;
/*!40101 SET
@OLD_COLLATION_CONNECTION=@@COLLATION
_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `votesystem`
--
-- --------------------------------------------------------
--
-- Table structure for table `admin`
--
--
-- Dumping data for table `admin`
--
-- --------------------------------------------------------
--
-- Table structure for table `candidates`
--
-- --------------------------------------------------------
--
-- Table structure for table `positions`
--
-- --------------------------------------------------------
--
-- Table structure for table `voters`
--
-- --------------------------------------------------------
--
-- Table structure for table `votes`
--
--
-- Indexes for dumped tables
--
--
-- Indexes for table `admin`
--
ALTER TABLE `admin`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `candidates`
--
ALTER TABLE `candidates`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `positions`
--
ALTER TABLE `positions`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `voters`
--
ALTER TABLE `voters`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `votes`
--
ALTER TABLE `votes`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `admin`
--
ALTER TABLE `admin`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `candidates`
--
ALTER TABLE `candidates`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT=18;
--
-- AUTO_INCREMENT for table `positions`
--
ALTER TABLE `positions`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT=8;
--
-- AUTO_INCREMENT for table `voters`
--
ALTER TABLE `voters`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `votes`
--
ALTER TABLE `votes`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT=81;
COMMIT;
/*!40101 SET
CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET
_CLIENT */;
/*!40101 SET
CHARACTER_SET_RESULTS=@OLD_CHARACTER_SE
T_RESULTS */;
/*!40101 SET
COLLATION_CONNECTION=@OLD_COLLATION_CO
NNECTION */;
ballot_modal.php
conn.php
<?php
$conn = new mysqli('localhost', 'root', '',
'votesystem');
if ($conn->connect_error) {
die("Connection failed: " . $conn-
>connect_error);
}
?>
footer.php
<footer class="main-footer">
<div class="container">
<div class="pull-right hidden-xs">
</div>
<strong>ONLINE VOTING MANAGMENT
SYSTEM</strong>
</div>
<!-- /.container -->
</footer>
header.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<title>Voting System using PHP</title>
<!-- Tell the browser to be responsive to screen
width -->
<meta content="width=device-width, initial-
scale=1, maximum-scale=1, user-scalable=no"
name="viewport">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet"
href="bower_components/bootstrap/dist/css/bootstrap
.min.css">
<!-- iCheck for checkboxes and radio inputs -->
<link rel="stylesheet" href="plugins/iCheck/all.css">
<!-- DataTables -->
<link rel="stylesheet"
href="bower_components/datatables.net-bs/css/dataTa
bles.bootstrap.min.css">
<!-- Font Awesome -->
<link rel="stylesheet"
href="bower_components/font-awesome/css/font-
awesome.min.css">
<!-- Theme style -->
<link rel="stylesheet"
href="dist/css/AdminLTE.min.css">
<!-- AdminLTE Skins. Choose a skin from the
css/skins
folder instead of downloading all of them to reduce
the load. -->
<link rel="stylesheet" href="dist/css/skins/_all-
skins.min.css">
<style>
.mt20{
margin-top: 20px;
}
.title{
font-size: 50px;
}
#candidate_list{
margin-top:20px;
}
#candidate_list ul{
list-style-type:none;
}
#candidate_list ul li{
margin:0 30px 30px 0;
vertical-align:top
}
.clist{
margin-left: 20px;
}
.cname{
font-size: 25px;
}
.votelist{
font-size: 17px;
}
</style>
</head>
navbar.php
<header class="main-header">
<nav class="navbar navbar-static-top">
<div class="container">
<div class="navbar-header">
<a href="#"
class="navbar-brand"><b>Voting</b>System</a>
<button type="button" class="navbar-toggle
collapsed" data-toggle="collapse" data-target="#navbar-
collapse">
<i class="fa fa-bars"></i>
</button>
</div>
scripts.php
$('#searchBox').on('keyup', function(){
bookTable.search(this.value).draw();
});
})
</script>
session.php
<?php
include 'includes/conn.php';
session_start();
if(isset($_SESSION['voter'])){
$sql = "SELECT * FROM voters WHERE id = '".
$_SESSION['voter']."'";
$query = $conn->query($sql);
$voter = $query->fetch_assoc();
}
else{
header('location: index.php');
exit();
}
?>
slugify.php
<?php
function slugify($string){
$preps = array('in', 'at', 'on', 'by', 'into', 'off', 'onto',
'from', 'to', 'with', 'a', 'an', 'the', 'using', 'for');
$pattern = '/\b(?:' . join('|', $preps) . ')\b/i';
$string = preg_replace($pattern, '', $string);
$string = preg_replace('~[^\\pL\d]+~u', '-', $string);
$string = trim($string, '-');
$string = iconv('utf-8', 'us-ascii//TRANSLIT', $string);
$string = strtolower($string);
$string = preg_replace('~[^-\w]+~', '', $string);
return $string;
}
?>
home.php
<div class="content-wrapper">
<div class="container">
foreach($_SESSION['error'] as $error){
echo "
<li>".
$error."</li>
";
}
?>
</ul>
</div>
<?php
unset($_SESSION['error']);
}
if(isset($_SESSION['success'])){
echo "
<div class='alert alert-
success alert-dismissible'>
<button type='button'
class='close' data-dismiss='alert' aria-
hidden='true'>×</button>
<h4><i class='icon fa
fa-check'></i> Success!</h4>
".$_SESSION['success']."
</div>
";
unset($_SESSION['success']);
}
?>
<?php
$sql = "SELECT * FROM votes
WHERE voters_id = '".$voter['id']."'";
$vquery = $conn->query($sql);
if($vquery->num_rows > 0){
?>
<div class="text-center">
<h3>You have already
voted for this election.</h3>
<a href="#view" data-
toggle="modal" class="btn btn-flat btn-primary btn-
lg">View Ballot</a>
</div>
<?php
}
else{
?>
<!-- Voting Ballot -->
<form method="POST"
id="ballotForm" action="submit_ballot.php">
<?php
include
'includes/slugify.php';
$candidate = '';
$sql = "SELECT *
FROM positions ORDER BY priority ASC";
$query =
$conn->query($sql);
while($row
= $query->fetch_assoc()){
$sql =
"SELECT * FROM candidates WHERE position_id='".
$row['id']."'";
$cquery = $conn->query($sql);
while($crow = $cquery->fetch_assoc()){
$slug = slugify($row['description']);
$checked = '';
if(isset($_SESSION['post'][$slug])){
$value = $_SESSION['post'][$slug];
if(is_array($value)){
foreach($value as $val){
if($val == $crow['id']){
$checked = 'checked';
else{
if($value == $crow['id']){
$checked = 'checked';
}
}
$candidate .= '
<li>
</li>
';
}
echo '
<div class="row">
<div class="col-xs-12">
<h3 class="box-title"><b>'.
$row['description'].'</b></h3>
</div>
<div class="box-body">
<p>'.$instruct.'
<span class="pull-right">
<button type="button"
class="btn btn-success btn-sm btn-flat reset" data-
desc="'.slugify($row['description']).'"><i class="fa fa-
refresh"></i> Reset</button>
</span>
</p>
<div id="candidate_list">
<ul>
'.$candidate.'
</ul>
</div>
</div>
</div>
</div>
</div>
';
$candidate = '';
?>
<div class="text-center">
<button
type="button" class="btn btn-success btn-flat"
id="preview"><i class="fa fa-file-text"></i>
Preview</button>
<button
type="submit" class="btn btn-primary btn-flat"
name="vote"><i class="fa fa-check-square-o"></i>
Submit</button>
</div>
</form>
<!-- End Voting Ballot -->
<?php
}
?>
</div>
</div>
</section>
</div>
</div>
$('#preview').click(function(e){
e.preventDefault();
var form = $('#ballotForm').serialize();
if(form == ''){
$('.message').html('You must vote atleast
one candidate');
$('#alert').show();
}
else{
$.ajax({
type: 'POST',
url: 'preview.php',
data: form,
dataType: 'json',
success: function(response){
if(response.error){
var errmsg = '';
var messages =
response.message;
for (i in messages) {
errmsg +=
messages[i];
}
$
('.message').html(errmsg);
$('#alert').show();
}
else{
$
('#preview_modal').modal('show');
$
('#preview_body').html(response.list);
}
}
});
}
});
});
</script>
</body>
</html>
index.php
<?php
session_start();
if(isset($_SESSION['admin'])){
header('location: admin/home.php');
}
if(isset($_SESSION['voter'])){
header('location: home.php');
}
?>
<?php include 'includes/header.php'; ?>
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<b>Voting System</b>
</div>
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your
session</p>
login.php
<?php
session_start();
include 'includes/conn.php';
if(isset($_POST['login'])){
$voter = $_POST['voter'];
$password = $_POST['password'];
}
else{
$_SESSION['error'] = 'Input voter credentials
first';
}
header('location: index.php');
?>
logout.php
<?php
session_start();
session_destroy();
header('location: index.php');
?>
preview.php
<?php
include 'includes/session.php';
include 'includes/slugify.php';
$output = array('error'=>false,'list'=>'');
while($row = $query->fetch_assoc()){
$position = slugify($row['description']);
$pos_id = $row['id'];
if(isset($_POST[$position])){
if($row['max_vote'] > 1){
if(count($_POST[$position]) >
$row['max_vote']){
$output['error'] = true;
$output['message'][] = '<li>You
can only choose '.$row['max_vote'].' candidates for '.
$row['description'].'</li>';
}
else{
foreach($_POST[$position] as
$key => $values){
$sql = "SELECT * FROM
candidates WHERE id = '$values'";
$cmquery = $conn-
>query($sql);
$cmrow = $cmquery-
>fetch_assoc();
$output['list'] .= "
<div class='row
votelist'>
<span class='col-sm-4'><span
class='pull-right'><b>".$row['description']."
:</b></span></span>
<span class='col-sm-8'>".
$cmrow['firstname']." ".$cmrow['lastname']."</span>
</div>
";
}
}
}
else{
$candidate = $_POST[$position];
$sql = "SELECT * FROM candidates
WHERE id = '$candidate'";
$csquery = $conn->query($sql);
$csrow = $csquery->fetch_assoc();
$output['list'] .= "
<div class='row votelist'>
<span class='col-sm-4'><span class='pull-
right'><b>".$row['description']." :</b></span></span>
<span class='col-sm-8'>".
$csrow['firstname']." ".$csrow['lastname']."</span>
</div>
";
}
echo json_encode($output);
?>
submit_ballot.php
<?php
include 'includes/session.php';
include 'includes/slugify.php';
if(isset($_POST['vote'])){
if(count($_POST) == 1){
$_SESSION['error'][] = 'Please vote atleast
one candidate';
}
else{
$_SESSION['post'] = $_POST;
$sql = "SELECT * FROM positions";
$query = $conn->query($sql);
$error = false;
$sql_array = array();
while($row = $query->fetch_assoc()){
$position =
slugify($row['description']);
$pos_id = $row['id'];
if(isset($_POST[$position])){
if($row['max_vote'] > 1){
}
else{
$candidate =
$_POST[$position];
$sql_array[] = "INSERT
INTO votes (voters_id, candidate_id, position_id)
VALUES ('".$voter['id']."', '$candidate', '$pos_id')";
}
if(!$error){
foreach($sql_array as $sql_row){
$conn->query($sql_row);
}
unset($_SESSION['post']);
$_SESSION['success'] = 'Ballot
Submitted';
}
}
else{
$_SESSION['error'][] = 'Select candidates to
vote first';
}
header('location: home.php');
?>
CHAPTER – 7
Home page
Admin view
Login page
Username: admin Password: password
Voters
Positions
Candidates list
Ballot Position
Title
Users view