A secure, web-based voting system built with PHP and MySQL that allows administrators to manage elections and voters to cast their votes electronically.
- Admin Panel: Secure admin interface with session-based authentication
 - Voter Authentication: OTP-based verification system for secure voter access
 - Password Management: Forgot password functionality with email verification
 - Session Security: Protected routes and secure session handling
 
- Create Elections: Add new elections with customizable parameters
 - Edit Elections: Modify existing election details
 - Delete Elections: Remove elections when needed
 - Election Status: Automatic status calculation (Active/Inactive) based on dates
 - Candidate Management: Add and manage candidates for each election
 
- Voter Registration: Secure voter registration process
 - OTP Verification: Two-factor authentication via email
 - Voting Interface: User-friendly voting interface
 - Vote Validation: Prevents duplicate voting
 - Real-time Results: Live election results display
 
- Live Results: Real-time voting results
 - Result Visualization: Clear presentation of election outcomes
 - Vote Counting: Accurate vote tallying system
 
- Backend: PHP 7.4+
 - Database: MySQL 5.7+
 - Frontend: HTML5, CSS3, JavaScript
 - UI Framework: Bootstrap 4
 - Email Service: PHPMailer for OTP delivery
 - Server: Apache (XAMPP/WAMP)
 
Before running this project, ensure you have:
- XAMPP or WAMP server installed
 - PHP 7.4 or higher
 - MySQL 5.7 or higher
 - Apache web server
 - Composer (for PHPMailer dependencies)
 
git clone https://github.com/yourusername/onlinevotingsystem.git
cd onlinevotingsystemcomposer install- Start your XAMPP/WAMP server
 - Open phpMyAdmin: 
http://localhost/phpmyadmin - Create a new database named 
onlinevotingsystem - Import the database schema from 
assets/onlinevotingsystem.sqlfile- In phpMyAdmin, select your database
 - Click on "Import" tab
 - Choose the SQL file and click "Go"
 
 - Important: The SQL file contains only table structure (no sample data)
 
Update the database connection in admin/inc/config.php:
$db = mysqli_connect("localhost", "root", "", "onlinevotingsystem") 
    or die("Connectivity Failed");Configure PHPMailer settings for OTP delivery in the relevant files:
forgot_password_request.phpotp_verification.phpverify_otp.php
Important: By default, all new user accounts are created with user_role = 'Voter'. To access the admin panel, you need to:
- Register a new account through the voter interface
 - Access phpMyAdmin and go to the 
userstable - Edit the user record and change 
user_rolefrom'Voter'to'Admin' - Save the changes
 
Alternative Method (SQL Command):
UPDATE users SET user_role = 'Admin' WHERE username = 'your_username';- Admin Panel: 
http://localhost/onlinevotingsystem/admin/ - Voter Interface: 
http://localhost/onlinevotingsystem/ 
CREATE TABLE `elections` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `election_topic` varchar(255) DEFAULT NULL,
  `no_of_candidates` int(11) DEFAULT NULL,
  `starting_date` date DEFAULT NULL,
  `ending_date` date DEFAULT NULL,
  `status` varchar(45) DEFAULT NULL,
  `inserted_by` varchar(255) DEFAULT NULL,
  `inserted_on` date DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;CREATE TABLE `candidate_details` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `election_id` int(11) DEFAULT NULL,
  `candidate_name` varchar(255) DEFAULT NULL,
  `party_details` text DEFAULT NULL,
  `candidate_photo` text DEFAULT NULL,
  `inserted_by` varchar(255) DEFAULT NULL,
  `inserted_on` date DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `email` varchar(45) DEFAULT NULL,
  `mobile_number` varchar(45) DEFAULT NULL,
  `password` text DEFAULT NULL,
  `user_role` varchar(45) DEFAULT 'Voter',
  `otp` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;CREATE TABLE `votings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `election_id` int(11) DEFAULT NULL,
  `voters_id` int(11) DEFAULT NULL,
  `candidate_id` int(11) NOT NULL,
  `vote_date` date DEFAULT NULL,
  `vote_time` time DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;- Access: 
http://localhost/onlinevotingsystem/admin/ - Default credentials: Set during initial setup
 
- Add Election: Create new elections with start/end dates
 - Edit Election: Modify existing election details
 - Delete Election: Remove elections (use with caution)
 
- Add Candidates: Upload candidate photos and details
 - Edit Candidates: Modify candidate information
 - View Results: Monitor election progress and results
 
- Voters register with email and phone number
 - System sends OTP for verification
 
- Login with verified credentials
 - Select active elections
 - Cast votes for preferred candidates
 - View real-time results
 
Update PHPMailer configuration in the relevant files:
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'your-email@gmail.com';
$mail->Password = 'your-app-password';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;- Update session keys in admin files
 - Configure proper file permissions
 - Set secure database credentials
 
- SQL Injection Protection: Prepared statements throughout
 - XSS Prevention: Input sanitization and output escaping
 - Session Security: Secure session management
 - Password Hashing: Secure password storage
 - OTP Verification: Two-factor authentication
 - Access Control: Role-based access restrictions
 
onlinevotingsystem/
βββ admin/                 # Admin panel files
β   βββ inc/              # Admin includes
β   β   βββ config.php    # Database configuration
β   β   βββ header.php    # Admin header
β   β   βββ navigation.php # Admin navigation
β   β   βββ add_elections.php # Add elections
β   β   βββ editElection.php # Edit elections
β   β   βββ add_candidates.php # Add candidates
β   β   βββ viewResults.php # View results
β   βββ index.php         # Admin main page
βββ voters/                # Voter interface
β   βββ inc/              # Voter includes
β   βββ index.php         # Voter main page
βββ assets/                # Static assets
β   βββ css/              # Stylesheets
β   βββ js/               # JavaScript files
β   βββ images/           # Images and photos
βββ vendor/                # Composer dependencies
βββ forgot_password_request.php # Password reset
βββ otp_verification.php  # OTP verification
βββ reset_password.php     # Password reset
βββ verify_otp.php        # OTP validation
βββ index.php             # Main entry point
- 
Database Connection Error
- Verify XAMPP/WAMP is running
 - Check database credentials in 
config.php - Ensure MySQL service is active
 - Note: The database starts empty - you need to create your first admin account
 
 - 
Email Not Sending
- Verify PHPMailer configuration
 - Check SMTP settings
 - Ensure proper email credentials
 
 - 
Session Issues
- Check PHP session configuration
 - Verify file permissions
 - Clear browser cookies
 
 - 
File Upload Errors
- Check upload directory permissions
 - Verify file size limits in PHP configuration
 - Ensure proper file types
 
 
- Monitor database performance
 - Update dependencies regularly
 - Backup database and files
 - Check error logs
 
- Keep PHP version updated
 - Monitor security advisories
 - Regular security audits
 - Update third-party libraries
 
- Fork the repository
 - Create a feature branch
 - Make your changes
 - Test thoroughly
 - Submit a pull request
 
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue on GitHub
 - Contact: [Your Contact Information]
 - Documentation: [Your Documentation URL]
 
- Server: Apache 2.4+
 - PHP: 7.4 or higher
 - MySQL: 5.7 or higher
 - Memory: Minimum 128MB RAM
 - Storage: Minimum 100MB free space
 - Browser: Modern browsers (Chrome, Firefox, Safari, Edge)
 
- Update database credentials
 - Configure production email settings
 - Set proper file permissions
 - Enable HTTPS
 - Configure backup systems
 - Set up monitoring
 
FROM php:7.4-apache
COPY . /var/www/html/
RUN docker-php-ext-install mysqli
EXPOSE 80Note: This is a development version. For production use, ensure proper security measures, SSL certificates, and regular security audits.