Onlinevoting System Project In Php And Mysql Source Code Github Link |best| May 2026
// Check if already voted (extra safety) $check = $pdo->prepare("SELECT has_voted FROM voters WHERE id = ?"); $check->execute([$voter_id]); if($check->fetchColumn() == 1) throw new Exception("Already voted"); // Insert vote record $insert = $pdo->prepare("INSERT INTO votes (voter_id, candidate_id) VALUES (?, ?)"); $insert->execute([$voter_id, $candidate_id]); // Update voter status $update = $pdo->prepare("UPDATE voters SET has_voted = 1 WHERE id = ?"); $update->execute([$voter_id]); // Increment candidate vote count $increment = $pdo->prepare("UPDATE candidates SET vote_count = vote_count + 1 WHERE id = ?"); $increment->execute([$candidate_id]); $pdo->commit(); $_SESSION['has_voted'] = 1; echo json_encode(["status" => "success", "message" => "Vote cast successfully!"]); catch(Exception $e) $pdo->rollBack(); echo json_encode(["status" => "error", "message" => $e->getMessage()]);
To clone using Git:
🔗 https://github.com/yourusername/online-voting-system-php-mysql (Replace with your actual GitHub link. If you are reading this and the link is missing, search on GitHub for "online voting system php mysql" or use the code below.) // Check if already voted (extra safety) $check
| Column | Type | Description | | :--- | :--- | :--- | | id | INT(11) AUTO_INCREMENT | Primary Key | | fullname | VARCHAR(100) | Voter's full name | | email | VARCHAR(100) | Unique login credential | | password | VARCHAR(255) | Hashed using password_hash() | | voter_id_card | VARCHAR(50) | Unique voter number | | is_approved | TINYINT(1) | 0 = Pending, 1 = Approved | | has_voted | TINYINT(1) | 0 = No, 1 = Yes |
?> The vote.php page uses JavaScript to submit votes without reloading: $(document)
🔗 👉 https://github.com/yourusername/online-voting-system-php-mysql 👈
In the digital age, the demand for secure, efficient, and transparent online voting mechanisms has skyrocketed. From student council elections in universities to corporate board voting and large-scale association polls, an eliminates paper waste, reduces manual counting errors, and allows remote participation. function(e) let candidate_id = $(this).data('candidate-id')
$(document).on('click', '.vote-btn', function(e) let candidate_id = $(this).data('candidate-id'); if(confirm("Are you sure you want to vote for this candidate? This action cannot be undone.")) $.ajax( url: 'vote_submit.php', type: 'POST', data: candidate_id: candidate_id, dataType: 'json', success: function(response) if(response.status == 'success') $('#vote-message').html('<div class="alert alert-success">Thank you for voting!</div>'); $('.vote-btn').prop('disabled', true); location.reload(); // Refresh to show updated results else $('#vote-message').html('<div class="alert alert-danger">'+response.message+'</div>'); );