Online Voting System Project in PHP
Introduction
The digital transformation is reshaping various sectors, including the electoral process. This article delves into the intricacies of an online voting system project in PHP, a technology that promises to make elections more secure, transparent, and accessible.
Core Modules
The system is designed with several modules to ensure a seamless voting experience:
- Admin Login: The Election Commission manages this portal, overseeing the entire election process.
- Candidate Document Verification: Admins can verify the credentials and documents of candidates.
- Candidate Login: Candidates can log in to upload their details and milestones.
- Voters Login: Voters receive a unique ID and password to cast their votes.
- Voters’ Candidate View: Allows voters to view candidate profiles and make informed decisions.
- Admin Dashboard: Provides overall functional rights, including data processing and handling.
- System-Generated Credentials: Unique IDs and passwords for both candidates and voters.
- Result Calculation Module: Automated calculation and display of election results.
- Election Creation Module: Admins can create new elections.
- Voting Conduction Module: Manages the actual voting process.
Advantages
- Efficiency: Speeds up the election process.
- Transparency: Voters can view the background of each candidate.
- Security: System-generated unique IDs and passwords ensure secure logins.
- Quick Results: Election results are available just 2 hours post-voting.
Disadvantages
- Security Risks: Potential for hacking of candidate or voter accounts.
- Accessibility: Not all voters have access to a computer or internet connection.
Conclusion
The online voting system project in PHP and MySQL offers a transformative approach to conducting elections. While there are challenges, particularly in terms of security and accessibility, the advantages make it a compelling option for modernizing electoral processes.
Sample Code
Database Setup
Create a MySQL database named ‘online_voting
‘ and a table named ‘users
‘:
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50),
password VARCHAR(50),
role ENUM('admin', 'voter')
);
Insert an admin and a voter for testing:
INSERT INTO users (username, password, role) VALUES ('admin', 'admin_pass', 'admin');
INSERT INTO users (username, password, role) VALUES ('voter', 'voter_pass', 'voter');
Create a file named 'index.php
‘:
<?php
session_start();
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "online_voting";
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$_SESSION['role'] = $row['role'];
if ($row['role'] == 'admin') {
header("Location: admin_dashboard.php");
} else {
header("Location: voter_dashboard.php");
}
} else {
echo "Invalid username or password";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="post" action="">
<label>Username:</label>
<input type="text" name="username" required><br>
<label>Password:</label>
<input type="password" name="password" required><br>
<input type="submit" value="Login">
</form>
</body>
</html>
Create a file named ‘admin_dashboard.php
‘:
<?php
session_start();
if ($_SESSION['role'] != 'admin') {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Admin Dashboard</title>
</head>
<body>
<h1>Welcome, Admin!</h1>
</body>
</html>
Create a file named ‘voter_dashboard.php
‘:
<?php
session_start();
if ($_SESSION['role'] != 'voter') {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Voter Dashboard</title>
</head>
<body>
<h1>Welcome, Voter!</h1>
</body>
</html>
In order to download the PDF, You must follow on Youtube. Once done, Click on Submit
Follow On YoutubeSubscribed? Click on Confirm