Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 1.68 KB

File metadata and controls

60 lines (44 loc) · 1.68 KB

Online Voting System

Online Voting System for Reality Shows is a web-based solution designed to manage all voting criteria for various types of reality shows in today's digital age.

Technologies Used

The system primarily utilizes the following technologies:

  • Frontend: HTML, CSS, JavaScript, Boostrap
  • Backend: PHP
  • Database: MySQL

No specific framework is employed as the system is entirely custom-built. Security measures have been implemented to ensure the safety of data.

Code Example

Below is a basic example of how the system might be implemented in PHP:

<?php
// Connect to MySQL database replace with your DB
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "voting_system";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Handle user vote
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $voter_id = $_POST["voter_id"];
    $contestant_id = $_POST["contestant_id"];

    // Check if the user has already voted
    $check_query = "SELECT * FROM votes WHERE voter_id = $voter_id";
    $result = $conn->query($check_query);

    if ($result->num_rows > 0) {
        echo "Sorry, you have already voted.";
    } else {
        // Insert vote into database
        $insert_query = "INSERT INTO votes (voter_id, contestant_id) VALUES ($voter_id, $contestant_id)";
        if ($conn->query($insert_query) === TRUE) {
            echo "Thank you for voting!";
        } else {
            echo "Error: " . $insert_query . "<br>" . $conn->error;
        }
    }
}

// Close database connection
$conn->close();
?>