Onlinevoting System Project In Php And Mysql Source Code Github Exclusive
In the modern digital era, the transition from paper-based processes to digital platforms is inevitable. One of the most critical areas where this transition is needed is the electoral process. Today, we are introducing an Online Voting System Project in PHP and MySQL, an exclusive, feature-rich solution designed to simplify and secure the voting process.
This project is perfect for final year students, researchers, and developers looking to understand the mechanics of web-based electoral systems.
| Role | Email | Password | |------|-------|----------| | Admin | admin@voting.com | admin123 | | Voter | voter1@example.com | voter123 |
(You can register new voters from the signup page)
<?php session_start(); include 'config/db.php';if(!isset($_SESSION['user_id'])) header("Location: login.php"); exit(); In the modern digital era, the transition from
// Check if user has already voted $checkVote = $conn->prepare("SELECT has_voted FROM users WHERE id = ?"); $checkVote->execute([$_SESSION['user_id']]); $user = $checkVote->fetch();
if($user['has_voted']) $_SESSION['error'] = "You have already voted!"; header("Location: dashboard.php"); exit();
// Verify election is active $election = $conn->query("SELECT election_status FROM election_settings WHERE id = 1"); $status = $election->fetchColumn();
if($status !== 'active') $_SESSION['error'] = "Election is not active."; header("Location: index.php"); exit(); // Check if user has already voted $checkVote
// Process vote based on POST data foreach($_POST['candidate'] as $position_id => $candidate_id) // Insert vote $insert = $conn->prepare("INSERT INTO votes (user_id, candidate_id, position_id) VALUES (?, ?, ?)"); $insert->execute([$_SESSION['user_id'], $candidate_id, $position_id]);
// Update candidate's vote count $updateCandidate = $conn->prepare("UPDATE candidates SET votes = votes + 1 WHERE id = ?"); $updateCandidate->execute([$candidate_id]);// Mark user as voted $markVoted = $conn->prepare("UPDATE users SET has_voted = 1 WHERE id = ?"); $markVoted->execute([$_SESSION['user_id']]);
$_SESSION['success'] = "Thank you! Your vote has been recorded."; header("Location: results.php"); ?>and finalizing in one transactional flow.
This snippet demonstrates the atomic nature of the voting process — checking, recording, updating, and finalizing in one transactional flow.
The database is the backbone of this system. The project includes a well-normalized database schema featuring tables such as:

