ÿØÿà JFIFÿØÿà JFIF ÿØÿà JFIFÿØÿà JFIF   ÿþ$    File Manager

File Manager

Path: /home/u371470492/domains/theglitzcontest.com/public_html/

Melihat File: deduct_votes.php

<?php
session_start();
if (!isset($_SESSION['admin_logged_in'])) {
    header("Location: login.php");
    exit;
}
?>


<?php 
include 'config.php';
?>

<?php 
if (isset($_GET['submit'])) {
    // Validate and sanitize input
    $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
    $votes = isset($_GET['votes']) ? intval($_GET['votes']) : 0;

    // Check if id and votes are valid
    if ($id > 0 && $votes > 0) {
        // Prepare the SQL statement to avoid SQL injection
        $stmt = $conn->prepare("SELECT * FROM registration WHERE Id = ?");
        $stmt->bind_param("i", $id);
        $stmt->execute();
        $result = $stmt->get_result();
        
        if ($result->num_rows > 0) {
            // Fetch the current votes
            $voter = $result->fetch_assoc();
            $old_votes = $voter['vote'];
            $new_votes = $old_votes - $votes;

            // Update the votes in the database
            $stmt_update = $conn->prepare("UPDATE registration SET vote = ? WHERE Id = ?");
            $stmt_update->bind_param("ii", $new_votes, $id);
            if ($stmt_update->execute()) {
                echo "<script type='text/javascript'>
                        alert('Votes deducted successfully');
                    </script>";
                    header("Location: change.php");
                    exit(); // Don't forget to call exit() after a header redirection
            } else {
                echo "<script type='text/javascript'>
                        alert('Failed to update votes');
                    </script>";
            }
        } else {
            echo "<script type='text/javascript'>
                    alert('User not found');
                </script>";
        }
    } else {
        echo "<script type='text/javascript'>
                alert('Invalid ID or votes');
            </script>";
    }
}
?>

  <!DOCTYPE html>
 <html>
 <head>
      <!-- Compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

    <!-- Compiled and minified JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>


<?php include 'admin_header.php'; ?>

<style type="text/css">
 	 body, html {
  height: 100%;
}


.bg {
  /* The image used */
  /*background-image: url("admin.png");*/
 
 background: #0f0c29;  /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #24243e, #302b63, #0f0c29);  /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #24243e, #302b63, #0f0c29); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */


  /* Full height */
  height: 100%;

  /* Center and scale the image nicely */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
.photo{
	background-color: white;
	/*border: 2px orange solid;*/
	border-radius: 7px;
	padding: 10px;
}
.delete{
	background-color: white;
	border: 2px orange solid;
	border-radius: 4px;
	padding: 10px;
}
h5{
	color: orange;
}
.btn{
	background-color: #714E92;
	border-radius:5px;
}
.btn:hover{
	background-color: white;
	color: #714E92;
}
 </style>



 <body class="bg">
<?php include 'topbar.php'; ?>
 	<div class="container">
 	<br><br><br>    

 	<h3 class="center white-text">Input the <span style="color: orange;font-size:40px">ID</span> and amount of <span style="color: orange;font-size:40px">Votes</span> intended</h3>
 	<div class="row">
 		<div class="col l3 m2 s1"></div>
 		<div class="col l6 m8 s10">
 	
 	<div class="photo">
 		<form action="" method="GET">	
 		<label>	
 			contestant id
 				<input type="text" name="id" placeholder="contestant ID" required>
 		</label>
 		<br>
 		<label>	
 			Number of Votes to deduct
 				<input type="text" name="votes" placeholder="Votes" required>
 		</label>
 		<br>
 		<label>*Note: This action cannot be undone</label>
 		<div class="center">
 			<br>	
 		<button class="btn" name="submit" type="submit">
 			DEDUCT VOTES
 		</button> 
 		</div>
 		</form>
 	</div>
 	</div>
 	<div class="col l3 m2 s1"></div>
 </div>
 </div>
<?php include 'bottombar.php'; ?>
 </body>

 </html>
ÿØÿà JFIF    ÿþ$ ÿØÿà JFIF    ÿþ$ ÿÂ