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

Voting

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

Voting

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

ONLINE VOTING SYSTEM

A Thesis
Submitted in partial fulfillment of the requirement
for the award of the Degree of

BACHELOR IN COMPUTER APPLICATION


IN
CS & IT

Submitted by
DRISHTDUMAN PRAJAPATI
(R16CA1CA0025)
Under esteemed supervision of

AISECT UNIVERSITY HAZARIBAG


2023-2023
APPROVAL OF THE GUIDE

Recommended that the thesis entitled “ONLINE VOTING


SYSTEM” presented by DRISHTDUMAN PRAJAPTI under
my supervision and guidance be accepted as fulfilling this part
of the requirements for the award of Degree of Bachelor of
Computer & Science. To the best of my knowledge, the
content of this thesis did not form a basis for the award of any
previous degree to anyone else.

Date: 04/07/2023
Mr. UDAY RANJAN
Assistant Professor
Dept. of CS & IT
Aisect University, Hazaribagh
DECLARATION CERTIFICATE

This is to certify the report entitled “ONLINE VOTING SYSTEM” Submitted by


DRISHTDUMAN PRAJAPATI,
Roll No. R20CA1CA0022, in the partial fullfillment of the requirement for the degree
Of Bachelor’s in Computer Application in Aisect University HAZARIBAGH, JHARKHAND
Is being carried out under my supervision. All the informative facts and figures in this
Documentation is based on My own experience and study during The Development of this
Project.

Guide:-
Mr. Uday Ranjan
CS & IT Aisect University Hazaribag

External Signature Internal Signature


ABSTRACT

The advent of technology has brought significant advancements in various aspects of


our lives, including the way we conduct elections. Online voting systems have
emerged as a potential solution to streamline the voting process, making it more
efficient, accessible, and secure. This abstract provides an overview of an online
voting system and its key features.

An online voting system is a digital platform designed to enable eligible voters to


cast their votes electronically over the internet. It offers a convenient alternative to
traditional voting methods, such as paper ballots and physical polling stations. The
system utilizes secure online channels to ensure the integrity, confidentiality, and
authentication of the voting process.
ACKNOWLEDGEMENT

I would like to express my online voting system to all those who gave
me the possibility to complete this report. Special thinks is due to my help
to Mr. Shivam Santosh, stimulating suggestions and encouragement helped
me in all time of fabrication process and writing this report.
It is always a great relief when you are done with something you have been
working on for a long time. It is the same when complete your final project.
Unlike other assignments, a project is successfully completed with the
mental and moral guidance of your mentors, principal, family, friends, etc.
While submitting a project, you are supposed to acknowledge all those
who helped you directly or indirectly in the completion of your project.
Learn how to write an acknowledgement for a university project .
Page Index
1. INTRODUCTION…………………………………………………………………….1-3

2. ANALYSIS……………………………………………………………………………..4-5

3. FEASIBILITY STUDY………………………………………………………………...6-9

4. DESIGN……………………………………………………………………………….10-20

5. SYSTEM MODLING……………………………………………………………… 21-26

CONCLUSION…………………………………………………………………………… 27

Table Index

1. DATABASE TABLE…………………………………………………………………26
1.1 ADMIN TABLE…………………………………………………………………...26
1.2 VOTER INFORMATION DATA TABLE………………………………………26
Figure Index

COMMUNICATION INTERFACE…………………………………………………15
DATA FLOW DIAGRAMS…………………………………………………………..17
DFD: LEVEL 0………………………………………………………………………17
DFD: LEVEL 1……………………………………………………………………….18
DFD: LEVEL 2……………………………………………………………………….19
ER DIAGRAMS
DIAGRAM

INTRODUCTION-:
“ONLINE VOTING SYSTEM” is an online voting technique. It is based on the other online
services like “ONLINE RESERVATION SYSTEM” .In this system people who have
citizenship of INDIA and whose age is above 18 years of any sex can give his\her vote online
without going to any polling booth. There is a DATABASE which is maintained by the
ELECTION COMMISION OF INDIA in which all the names of voter with complete
information is stored.

WORKING-:
In “ONLINE VOTING SYSTEM” a voter can use his\her voting right online without any
difficulty. He\She has to fill a registration form to register himself\herself. All the entries is
checked by the DATABASE which has already all information about the voter. If all the entries
are correct then a USER ID and PASSWORD is given to the voter, by using that ID and
PASSWORD he\she can use his\her vote. If conditions are wrong then that entry will be
discarded.
UNIT-1
INTRODUCTION

1.1 Purpose

In “ONLINE VOTING SYSTEM” a voter can use his\her voting right online without any
difficulty. He\She has to fill a registration form to register himself\herself. All the entries is
checked by the DATABASE which has already all information about the voter. If all the entries
are correct then a USER ID and PASSWORD is given to the voter, by using that ID and
PASSWORD he\she can use his\her vote. If conditions are wrong then that entry will be
discarded.

1.2 Scope

The scope of the project that is hosted on the server. There is a DATABASE which is
maintained by the ELECTION COMMISION OF INDIA in which all the names of voter with
complete information is stored.

1.3 Technologies to be used

This project will be a Web application to be developed in PHP having


• Database Design (My SQL)
• Form Design (HTML5)
• Coding (PHP)
• Testing (XAMPP SERVER)

1.4 Overview
✓ Project is related to Online Voting System.
✓ The project maintains two levels of users:-
• Administrator Level
• Voter Level
✓ Main facilities available in this project are:-
• Maintaining voter’s Identification.
• Providing online voting management.
• Providing Updation of voter’s information.
• Provide voter information to ELECTION COMMISION OF INDIA.
• ELECTION COMMISION OF INDIA maintains the complete
information of voter.
• Voter can give his\her vote from any part of India.
UNIT-2

OVERALL DESCRIPTION

2.1 Goals of proposed system

1. Planned approach towards working: - The working in the organization will be well planned
and organized. The data will be stored properly in data stores, which will help in retrieval of
information as well as its storage.
2. Accuracy: - The level of accuracy in the proposed system will be higher. All operation would
be done correctly and it ensures that whatever information is coming from the center is accurate.
3. Reliability: - The reliability of the proposed system will be high due to the above stated
reasons. The reason for the increased reliability of the system is that now there would be proper
storage of information.
4. No Redundancy: - In the proposed system utmost care would be that no information is
repeated anywhere, in storage or otherwise. This would assure economic use of storage space
and consistency in the data stored.
5. Immediate retrieval of information: - The main objective of proposed system is to provide
for a quick and efficient retrieval of information.
6. Immediate storage of information: - In manual system there are many problems to store the
largest amount of information.
7. Easy to Operate: - The system should be easy to operate and should be such that it can be
developed within a short period of time and fit in the limited budget of the user.

2.2 Background
ONLINE VOTING SYSTEM is a voting system by which any Voter can use his\her voting rights
from any where in India. ONLINE VOTING SYSTEM contains-:
• Voter’s information in database.
• Voter’s Names with ID.
• Voter’s vote in a database.
• Calculation of total number of votes.
Various operational works that are done in the system are:-
• Recording information of the Voter in Voter database.
• Checking of information filled by voter.
• Discard the false information.
• Each information is sent to ELECTION COMMISSION OF INDIA.

2.3 Project Requirements

Hardware Requirements (Processor RAM Disk Space)


Pentium II, Pentium III, Pentium IV, Higher 128 Mb or Higher 130 Mb

Software Requirements (Operating System Database)


Win-98, Win-XP, Linux, My SQL

2.4 User Characteristics


Every user should be:
✓ Comfortable with Internet Browser.
✓ He must have brief knowledge of voting system.
✓ He must also have basic knowledge of English too.

2.5 Constraints
✓ GUI is only in English.
✓ Login and password is used for identification of Voter.

2.6 Definitions of problems


• Not User Friendly: The existing system is not user friendly because the retrieval of data is
very slow and data is not maintained efficiently.
• Difficulty in report generating: We require more calculations to generate the final result
so it is generated at the end of the session. And the voter not get a single chance to change
his\her vote.
• Time consuming: Every work is done manually so we cannot generate report in the middle
of the session or as per the requirement because it is very time consuming.
UNIT-3
FEASIBILITY STUDY

Depending on the results of the initial investigation the survey is now expanded to a more detailed
feasibility study. “FEASIBILITY STUDY” is a test of system proposal according to its
workability, impact of the organization, ability to meet needs and effective use of the resources.
It focuses on these major questions:
1. What are the user’s demonstrable needs and how does a candidate system meet them?
2. What resources are available for given candidate system?
3. What are the likely impacts of the candidate system on the organization?
4. Whether it is worth to solve the problem?
During feasibility analysis for this project, following primary areas of interest are to be
considered. Investigation and generating ideas about a new system does this.
Steps in feasibility analysis
Eight steps involved in the feasibility analysis are:

• Form a project team and appoint a project leader.


• Prepare system flowcharts.
• Enumerate potential proposed system.
• Define and identify characteristics of proposed system.
• Determine and evaluate performance and cost effective of each proposed system.
• Weight system performance and cost data.
• Select the best-proposed system.
• Prepare and report final project directive to management.

3.1 Technical feasibility


A study of resource availability that may affect the ability to achieve an acceptable system. This
evaluation determines whether the technology needed for the proposed system is available or
not.
• Can the work for the project be done with current equipment existing software technology
& available personal?
• Can the system be upgraded if developed?
• If new technology is needed then what can be developed?

• This is concerned with specifying equipment and software that will successfully satisfy
the user requirement. The technical needs of the system may include:

Front-end and back-end selection


An important issue for the development of a project is the selection of suitable front-end and
back-end. When we decided to develop the project we went through an extensive study to
determine the most suitable platform that suits the needs of the organization as well as helps in
development of the project.
The aspects of our study included the following factors.

Front-end selection:
1. It must have a GUI that assists employees that are not from IT background.
2. Scalability and extensibility.
3. Flexibility.
4. Robustness.
5. According to the organization requirement and the culture.
6. Must provide excellent reporting features with good printing support.
7. Platform independent.
8. Easy to debug and maintain.
9. Event driven programming facility.
10. Front end must support some popular back end like Ms Access.

According to the above stated features we selected PHP as the front-end for
developing our project.

Back-end Selection:
1. Multiple user support.
2. Efficient data handling.
3. Provide inherent features for security.
4. Efficient data retrieval and maintenance.
5. Stored procedures.
6. Popularity.
7. Operating System compatible.
8. Easy to install.

9. Various drivers must be available.


10. Easy to implant with the Front-end.
According to above stated features we selected MY SQL as the backend.
The technical feasibility is frequently the most difficult area encountered at this stage. It is
essential that the process of analysis and definition be conducted in parallel with an assessment
to technical feasibility. It centers on the existing computer system and to what extent it can
support the proposed system.

3.2 Economical feasibility

Economic justification is generally the “Bottom Line” consideration for most systems. Economic
justification includes a broad range of concerns that includes cost benefit analysis. In this we
weight the cost and the benefits associated with the candidate system and if it suits the basic
purpose of the organization i.e. profit making, the project is making to the analysis and design
phase.
The financial and the economic questions during the preliminary investigation are
verified to estimate the following:
• The cost to conduct a full system investigation.
• The cost of hardware and software for the class of application being considered.
. The benefits in the form of reduced cost.
• The proposed system will give the minute information, as a result the
performance is improved
• This feasibility checks whether the system can be developed with the available funds.
The Online voting system does not require enormous amount of money to be developed.
This can be done economically if planned judicially, so it is economically feasible. The
cost of project depends upon the number of man-hours required.

3.3 Operational Feasibility

It is mainly related to human organizations and political aspects. The points to be


considered are:
• What changes will be brought with the system?
• What organization structures are disturbed?

• What new skills will be required? Do the existing staff members have these
skills? If not, can they be trained in due course of time?
The system is operationally feasible as it very easy for the End users to operate it. It only needs
basic information about Windows platform.

3.4 Schedule feasibility


Time evaluation is the most important consideration in the development of project. The time
schedule required for the developed of this project is very important since more development
time effect machine time, cost and cause delay in the development of other systems.
A reliable Online voting system can be developed in the considerable amount of time
UNIT-4
DESIGN

4.1 Software Requirement Specification

4.1.1 Objective:

The main objectives of system for Online voting system are:

• The objective of Online voting system is to help the organization in automating


the whole manual processing of the existing system.
• The main objective to develop the system is to make the accurate & efficient decisions
in different tasks at different time at different situations. The existing system is manual
so members of the unit generally face a lot of embarrassing situations many times. Now
they need to automate the whole process so as to make it more easy and accurate.
• System should support multi-user environment.
• System should be fully automated.
• System should provide concrete security features like creating users and assigning
privileges to users of the system.
• System should be capable to keep track of all the detailed descriptions of the client and
the whole details of services offered by the client organization.
• Various outputs (reports) should be available online any time.
• System should be able to handle extremely large volumes of data (i.e. Large database
support)

4.1.2 Scope:-

1. Advanced technology- It is an advanced technology used now a days. It increases


the E knowledge of the users which is very necessary for current generation.

2. Internet: It is an online facility and hence very useful for the users.
Voters can vote from any where at any time in India.
3. E-Mails: ELECTION COMMISION OF INDIA can send the error report to a
particular user if he\she entered false information.

4. E-SMS: People they have not internet connection they can not check the emails or
not have email they can be informed by SMS on their mobile. Today many websites
provide free SMS to the mobile. ELECTION COMMISION OF INDIA can use
these to send any information.

4.1.3 Advantages:

• Fast and easy service.

• The online voting system provides a less time consuming .

• It reduces the paper work and makes the work less tedious for ELESTION
COMMISION.

• It is a better way for voting.

• By this voting percentage will increase drastically.


Voter has no need to go to any polling booth ,so it is easy to use.

4.1.4 Technologies to be used:-


This project will be a Web application to be developed in PHP having
• Database Design (My SQL)
• Form Design (HTML 4.0)
• Coding (PHP)
• Testing (XAMP SERVER)

• Reporting Tool (Data Report)

4.1.5 OVERVIEW:

1. Requirements:

• FUNCTIONAL REQUIREMENTS:

• Registration of the voter is done by ELECTION COMMISION OF INDIA.

• ELECTION COMMISION OF INDIA can change the information any time if required.

• Registration of the Voter depends upon the information filled by the user.

• Voter is given a unique ID and PASSWORD.

Voter can give vote after login and entering the ID and PASSWORD.

• In the DATABASE information of every voter is stored.

• Database shows the information of every user.

• NON-FUNCTIONAL REQUIREMENTS:
1. Secure access of confidential data (user’s details). SSL can be used.
2. 24 X 7 availability.
3. Better component design to get better performance at peak time.
4. Flexible service based architecture will be highly desirable for future extension

2. Project Requirements

Hardware Requirements (Processor RAM Disk Space)


Pentium II, Pentium III, Pentium IV, Higher 64 Mb or Higher 130 Mb

Software Requirements (Operating System Database)


Window, My SQL

3. Software interface:

• Client on Internet: Web Browser, Operating System (Windows).

. Client on intranet: Client Software, Web Browser, Operating System (Windows).

• Web Server: WAMP Server, Operating System (Windows)

• Data Base server: MYSQL, Operating System (Windows).


4. Communication interface:

HTTP/HTT
HTML Client
PS

XAMPP
MYSQL
Server

Client TCP/IP
software
(System

Client side Application server Database


server

The above diagram shows the connectivity between the client side, application server and
database server. The client or customer can access the HTML server or client software. These
are connected to the Wamp Server (XAMPP) by a TCP/IP which is a communication protocol
used to connect the teachers or parents to the internet. This XAMPP Server now directly
communicates with the database made in MYSQL. All the enquires or data will be retrieved
from the database.
4.1.6 Summary:

“ONLINE VOTING SYSTEM” is an online voting technique. It is based on the other online
services like “ONLINE RESERVATION SYSTEM” .In this system people who have
citizenship of INDIA and whose age is above 18 years of any sex can give his\her vote online
without going to any polling booth. There is a DATABASE which is maintained by the
ELECTION COMMISION OF INDIA in which all the names of voter with complete
information is stored.

In “ONLINE VOTING SYSTEM” a voter can use his\her


voting right online without any difficulty. He\She has to fill a registration form to register
himself\herself. All the entries is checked by the DATABASE which has already all
information about the voter. If all the entries are correct then a USER ID and PASSWORD is
given to the voter, by using that ID and PASSWORD he\she can use his\her vote. If conditions
are wrong then that entry will be discarded.

4.2 Data Flow Diagram

DFD: Level 0

User
or
Administrator

System

Output
The above diagram is a 0-level DFD that only shows the flow of data between the various
and the system. In online voting system the Administrator is the controller of the system and
all the decisions are made by him. The Administrator can handle the entire voter and their
details, voting details etc. and view details of them and he can update that detail also.

DFD: Level 1:-

Login Voter
Process Registration
Process

Voter Voting
information Process Final
checking Report
process

DFD Level 1
The above shown diagram is a 1-level Data Flow Diagram for the Online voting system.
According to this DFD various process are done after login process. The Administrator can
register voter. The ELECTION COMMISION can register the voters and voter can use their
voting rights. The voter can view the final report after giving vote..

. DFD: Level 2
2.1:-
Login
Login Process

voter data stored data voting data final result

ElectionCommission

DFD: Level 2.1


The above shown diagram is a 2.1 level Data Flow Diagram for the Online voting
system. According to this DFD. The Administrator can register the voter
information. Administrator can allow or denies the voter. A voter can give vote if
all the information filled by him\her are correct.
UNIT-5
SYSTEM MODLING

Entity Relationship Diagram

Admin. Registration

Fail VOTER

id Pas
s

VOTING
Login

Voting Report

Report
View

The entity relationship diagram shows the relationship between the various users and their
attributes. There is a relationship between the election commission and voter.
The VOTER has different attributes to store their data to data base are follows:-
1. Name-Name contain first name, middle name, last name.
2. Age (should be above 18 years)
3. City
4. State
5. Father’s/Husband Name
6. Address
7. Phone number (Permanent)
8. Phone number (Mobile)
9. Email address

Data Base Tables:-


Admin Table:-

S. No. Field Name Data Type Description

1. Login id Varchar Login id for Admin.(Primary key)


2. Password Varchar Password for Login
3. Name Varchar Name of the Administrator

Voter information Data Table:-

S. No. Field Name Data Type Description

1. Login id Varchar Login id for Voter(Primary key)


2. Password Varchar Password for Login
3. Name Varchar Name of the voter
4. Father’s/Husband name Varchar Voter’s father or
husband name
5. House no. Varchar House no. of voter
6. Address Varchar Address of voter
7. City Varchar City of voter
8. Mobile Varchar Mobile No of voter
9. E-Mail Varchar E-Mail of voter

CONCLUSION

This Online Voting system will manage the Voter’s information by which voter can login and
use his voting rights. The system will incorporate all features of Voting system. Its provide
the tools for maintaining voter’s vote to every party and it count total no. of votes of every
party. There is a DATABASE which is maintained by the ELECTION COMMISION OF
INDIA in which all the names of voter with complete information is stored.
In this user who is above 18 year’s register his/her information on the database and when
he/she want to vote he/she has to login by his id and password and can vote to any party only
single time. Voting detail store in database and the result is displayed by calculation. By online
voting system percentage of voting is increases. It decreases the cost and time of voting process.
It is very easy to use and It is vary less time consuming. It is very easy to debug.
SOURCE CODE

PHP
Home page:-

<?php include 'includes/session.php'; ?>


<?php include 'includes/header.php'; ?>
<body class="hold-transition skin-blue layout-top-nav">
<div class="wrapper">

<?php include 'includes/navbar.php'; ?>

<div class="content-wrapper">
<div class="container">

<!-- Main content -->


<section class="content">
<?php
$parse = parse_ini_file('admin/config.ini', FALSE,
INI_SCANNER_RAW);
$title = $parse['election_title'];
?>
<h1 class="page-header text-center title"><b><?php echo
strtoupper($title); ?></b></h1>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<?php
if(isset($_SESSION['error'])){
?>
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-
dismiss="alert" aria-hidden="true">&times;</button>
<ul>
<?php
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'>&times;</button>
<h4><i class='icon fa fa-check'></i>
Success!</h4>
".$_SESSION['success']."
</div>
";
unset($_SESSION['success']);
}

?>

<div class="alert alert-danger alert-dismissible"


id="alert" style="display:none;">
<button type="button" class="close" data-
dismiss="alert" aria-hidden="true">&times;</button>
<span class="message"></span>
</div>

<?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';
}
}
}
$input = ($row['max_vote'] > 1) ?
'<input type="checkbox" class="flat-red '.$slug.'" name="'.$slug."[]".'"
value="'.$crow['id'].'" '.$checked.'>' : '<input type="radio" class="flat-red
'.$slug.'" name="'.slugify($row['description']).'" value="'.$crow['id'].'"
'.$checked.'>';
$image = (!empty($crow['photo']))
? 'images/'.$crow['photo'] : 'images/profile.jpg';
$candidate .= '
<li>
'.$input.'<button
type="button" class="btn btn-primary btn-sm btn-flat clist platform" data-
platform="'.$crow['platform'].'" data-fullname="'.$crow['firstname'].'
'.$crow['lastname'].'"><i class="fa fa-search"></i> Platform</button><img
src="'.$image.'" height="100px" width="100px" class="clist"><span class="cname
clist">'.$crow['firstname'].' '.$crow['lastname'].'</span>
</li>
';
}

$instruct = ($row['max_vote'] > 1) ?


'You may select up to '.$row['max_vote'].' candidates' : 'Select only one
candidate';

echo '
<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>
<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>
'.$candida
te.'
</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>

<?php include 'includes/footer.php'; ?>


<?php include 'includes/ballot_modal.php'; ?>
</div>

<?php include 'includes/scripts.php'; ?>


<script>
$(function(){
$('.content').iCheck({
checkboxClass: 'icheckbox_flat-green',
radioClass: 'iradio_flat-green'
});

$(document).on('click', '.reset', function(e){


e.preventDefault();
var desc = $(this).data('desc');
$('.'+desc).iCheck('uncheck');
});

$(document).on('click', '.platform', function(e){


e.preventDefault();
$('#platform').modal('show');
var platform = $(this).data('platform');
var fullname = $(this).data('fullname');
$('.candidate').html(fullname);
$('#plat_view').html(platform);
});

$('#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 Page :-

<?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> Online Voting System</b>
</div>

<div class="login-box-body">
<p class="login-box-msg"> Voters Sign In Session</p>

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


<div class="form-group has-feedback">
<input type="text" class="form-control" name="voter"
placeholder="Voter's ID" required>
<span class="glyphicon glyphicon-user form-control-
feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" name="password"
placeholder="Password" required>
<span class="glyphicon glyphicon-lock form-control-
feedback"></span>
</div>
<div class="row">
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block
btn-flat" name="login"><i class="fa fa-sign-in"></i> Sign In</button>
</div>
</div>
</form>
</div>
<?php
if(isset($_SESSION['error'])){
echo "
<div class='callout callout-danger text-center mt20'>
<p>".$_SESSION['error']."</p>
</div>
";
unset($_SESSION['error']);
}
?>
</div>

<?php include 'includes/scripts.php' ?>


</body>
</html>

Login Page :

<?php
session_start();
include 'includes/conn.php';

if(isset($_POST['login'])){
$voter = $_POST['voter'];
$password = $_POST['password'];

$sql = "SELECT * FROM voters WHERE voters_id = '$voter'";


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

if($query->num_rows < 1){


$_SESSION['error'] = 'Cannot find voter with the ID';
}
else{
$row = $query->fetch_assoc();
if(password_verify($password, $row['password'])){
$_SESSION['voter'] = $row['id'];
}
else{
$_SESSION['error'] = 'Incorrect password';
}
}

}
else{
$_SESSION['error'] = 'Input voter credentials first';
}

header('location: index.php');

?>

Logout :-

<?php
session_start();
session_destroy();

header('location: index.php');
?>
Submit Page:

<?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){
if(count($_POST[$position]) > $row['max_vote']){
$error = true;
$_SESSION['error'][] = 'You can only choose
'.$row['max_vote'].' candidates for '.$row['description'];
}
else{
foreach($_POST[$position] as $key => $values){
$sql_array[] = "INSERT INTO votes (voters_id,
candidate_id, position_id) VALUES ('".$voter['id']."', '$values', '$pos_id')";
}

}
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');

?>

You might also like