Online Voting System Project in PHP and MySQL
An online voting system is a web-based application that allows users to cast their votes electronically. This project aims to provide a secure, efficient, and transparent way of conducting online elections.
Features:
Source Code on GitHub:
You can find the source code for this project on GitHub:
Repository: https://github.com/your-username/online-voting-system
Database Schema:
The database schema for this project is as follows:
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255),
email VARCHAR(255),
password VARCHAR(255)
);
CREATE TABLE candidates (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255),
description TEXT
);
CREATE TABLE votes (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
candidate_id INT,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (candidate_id) REFERENCES candidates(id)
);
PHP Code:
The PHP code for this project is as follows:
config.php
<?php
$host = 'localhost';
$username = 'your_username';
$password = 'your_password';
$database = 'online_voting_system';
$conn = mysqli_connect($host, $username, $password, $database);
if (!$conn)
die("Connection failed: " . mysqli_connect_error());
?>
register.php
<?php
include 'config.php';
if (isset($_POST['register']))
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$query = "INSERT INTO users (name, email, password) VALUES ('$name', '$email', '$password')";
$result = mysqli_query($conn, $query);
if ($result)
header('Location: login.php');
else
echo "Error: " . mysqli_error($conn);
?>
login.php
<?php
include 'config.php';
if (isset($_POST['login']))
$email = $_POST['email'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE email = '$email' AND password = '$password'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0)
header('Location: index.php');
else
echo "Invalid email or password";
?>
index.php
<?php
include 'config.php';
if (isset($_POST['vote']))
$candidate_id = $_POST['candidate_id'];
$user_id = $_SESSION['user_id'];
$query = "INSERT INTO votes (user_id, candidate_id) VALUES ('$user_id', '$candidate_id')";
$result = mysqli_query($conn, $query);
if ($result)
echo "Vote cast successfully";
else
echo "Error: " . mysqli_error($conn);
?>
Portable Version:
To make this project portable, you can use a tool like XAMPP or WAMP to create a local server on your machine. You can also use a portable MySQL database like SQLite.
Security Measures:
This is a basic online voting system project in PHP and MySQL. You can improve it by adding more features and security measures. You can also use a framework like Laravel or CodeIgniter to make it more robust and scalable.
Several online voting system projects built with PHP and MySQL are available on GitHub, offering features like admin panels and secure voter registration
. These systems typically run on local server environments like , making them highly portable and easy to set up Popular GitHub Repositories php-voting-system
: Includes an AdminLTE theme for a professional dashboard and handles election management through a full admin panel University-Online-Voting-System
: A structured project designed for campus elections, featuring clear installation steps and a pre-configured database schema Online-Voting-System-using-php-and-mysql
: A basic, open-source implementation focused on core voting functionality like candidate listing and real-time vote counts Standard Features Most of these portable projects include: Voter Registration & Login : Validates users before they can cast a vote Admin Dashboard
: Allows admins to create elections, manage candidate profiles, and monitor results Real-time Results
: Automatically calculates and displays voting tallies as they come in Installation Guide (General) To run these projects portably on your local machine: Install a Local Server : Download and start (Apache and MySQL) Download Source Code : Clone or download the ZIP from the GitHub repo and place it in the Setup Database phpMyAdmin to create a new database and import the file included in the project folder : Access the system via localhost/your_folder_name in your web browser php-voting-system · GitHub Topics Online Voting System Project in PHP and MySQL
Online Voting System using PHP and Mysql with AdminLTE Theme. online-voting-with-admin-panel. Updated on Mar 31, 2023. online-voting-system · GitHub Topics
$_SESSION) restrict page access to logged-in users only.password_hash() (Bcrypt/Argon2) rather than plain text.status column in the database. Once a user votes, the status changes to "voted", preventing duplicate submissions.1. Download the Source Code You can clone or download the repository from GitHub.
Search for the repository or use the link provided at the end of this post.
2. Extract the Files
online_voting_system).C:\xampp\htdocs\ (for XAMPP users).3. Create the Database
http://localhost/phpmyadmin.voting_db.database or db folder of the source code) into this new database.4. Configure the Connection
config.php or db.php.<?php
$host = "localhost";
$user = "root";
$password = ""; // Default XAMPP password is empty
$dbname = "voting_db";
$conn = mysqli_connect($host, $user, $password, $dbname);
?>
5. Run the Application
http://localhost/online_voting_system.readme.txt of the project) to log in as Admin.Once you have the base portable voting system, you can add: User Registration : Users can register to vote
These additions maintain portability as long as no server-specific extensions (beyond PHP/MySQL) are required.