diff --git a/results.php b/results.php index 4f0c0d4..724ff41 100644 --- a/results.php +++ b/results.php @@ -1,30 +1,42 @@ exec('TRUNCATE TABLE votes'); $message = 'All votes have been cleared.'; } else { - if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin']) { - $error = 'Invalid password'; - } + // Optional: handle unauthorized cleanup attempt } } +// Handle logout if (isset($_GET['logout'])) { session_destroy(); header('Location: results.php'); exit; } + +$is_loggedin = isset($_SESSION['loggedin']) && $_SESSION['loggedin']; ?> @@ -37,7 +49,7 @@ if (isset($_GET['logout'])) {
- +

Voting Results

Logout @@ -57,9 +69,10 @@ if (isset($_GET['logout'])) { $pdo = db(); $stmt = $pdo->query("SELECT website_number, COUNT(*) as votes FROM votes WHERE category = 'beauty' GROUP BY website_number ORDER BY votes DESC"); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); - if (empty($results)): ?> -

No votes yet.

- + if (empty($results)): + echo "

No votes yet for this category.

"; + else: + ?>
+
+
+

Raw Votes

+ query("SELECT id, voter_name, category, website_number, created_at FROM votes ORDER BY created_at DESC"); + $raw_votes = $stmt->fetchAll(PDO::FETCH_ASSOC); + if (empty($raw_votes)): + echo "

No votes have been cast yet.

"; + else: + ?> + + + + + + + + + + + + + + + + + + + + + +
IDVoter NameCategoryWebsite NumberTimestamp
+ +
+
+
@@ -108,6 +158,7 @@ if (isset($_GET['logout'])) {

View Results

+

You must be logged in to see the voting results.

@@ -115,7 +166,7 @@ if (isset($_GET['logout'])) {
-

+

@@ -125,4 +176,4 @@ if (isset($_GET['logout'])) {
- + \ No newline at end of file diff --git a/submit_vote.php b/submit_vote.php index 7f38821..2711d34 100644 --- a/submit_vote.php +++ b/submit_vote.php @@ -30,7 +30,7 @@ if (!$data) { $voterName = $data['voter_name'] ?? ''; $category = $data['category'] ?? ''; $website_numbers_str = $data['website_numbers'] ?? ''; -$website_numbers = !empty($website_numbers_str) ? explode(',', $website_numbers_str) : []; +$website_numbers = !empty($website_numbers_str) ? array_map('trim', explode(',', $website_numbers_str)) : []; if (empty($voterName) || empty($category) || !in_array($category, ['beauty', 'funny'])) { echo json_encode(['success' => false, 'error' => 'Invalid data provided.']);