ÿØÿà JFIFÿØÿà JFIF ÿØÿà JFIFÿØÿà JFIF ÿþ$
<?php
session_start();
if (!isset($_SESSION['admin_logged_in'])) {
header("Location: login.php");
exit;
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
include 'config.php';
// Validate and sanitize input
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
$votes = isset($_POST['votes']) ? intval($_POST['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;
// Prepare the UPDATE query
$stmt_update = $conn->prepare("UPDATE registration SET vote = ? WHERE Id = ?");
$stmt_update->bind_param("ii", $new_votes, $id);
if ($stmt_update->execute()) {
echo "<script>alert('Votes added successfully');</script>";
header("Location: change.php");
exit();
} else {
echo "<script>alert('Failed to update votes');</script>";
}
} else {
echo "<script>alert('User not found');</script>";
}
} else {
echo "<script>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>
<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">
<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="POST">
<label>
contestant id
<input type="text" name="id" placeholder="contestant ID" required>
</label>
<br>
<label>
Number of Votes
<input type="number" 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">
ADD VOTES
</button>
</div>
</form>
</div>
</div>
<div class="col l3 m2 s1"></div>
</div>
</div>
<?php include 'bottombar.php'; ?>
</body>
</html>
ÿØÿà JFIF ÿþ$
ÿØÿà JFIF ÿþ$
ÿÂ