forked from austindebruyn/media-poll
/
finalvote.php
executable file
·54 lines (46 loc) · 1.64 KB
/
finalvote.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
session_start();
require_once 'includes/connect.php';
require_once 'includes/forceopen.php';
//Make sure you aren't trying to double vote
if (hasVoted()) {
header("Location: /thanks");
exit();
}
if ($_SESSION['confirmcheck'] !== "CONFIRMED")
die("<h1>eror</h1>");
$totalvotes = $_SESSION['totalvotes'];
for ($i=0; $i<$totalvotes; $i+=1) {
$vid = $_SESSION['ballotData'][$i]['vid'];
$title = $_SESSION['ballotData'][$i]['title'];
$viewCount = $_SESSION['ballotData'][$i]['viewCount'];
$smallthumb = $_SESSION['ballotData'][$i]['smallthumb'];
$bigthumb = $_SESSION['ballotData'][$i]['bigthumb'];
$artist = $_SESSION['ballotData'][$i]['artist'];
$artisturl = $_SESSION['ballotData'][$i]['artisturl'];
$title = $con->escape_string($title);
$artist = $con->escape_string($artist);
$sql = "SELECT * from `votes` WHERE `vid`='".$_SESSION['ballotData'][$i]['vid']."'";
$result = $con->query($sql);
if ($result->num_rows < 1) {
$sql = "INSERT INTO votes (`vid`, `name`, `tally`, `views`, `smallthumb`, `bigthumb`,
`artist`, `artisturl`, `dAdded`, `dLastvoted`) ".
"VALUES ('$vid', '$title', 1, $viewCount, '$smallthumb', '$bigthumb',
'$artist', '$artisturl', CURDATE(), CURDATE())";
$con->query($sql);
}
else
{
//Add 1 to the tally already recorded and update
$fetcher = $result->fetch_assoc();
$cnt = $fetcher['tally']+1;
$sql = "UPDATE `votes` SET `tally` = $cnt, `dLastvoted`=CURDATE() WHERE `vid`='".$vid."'";
$con->query($sql);
}
}
//Mark this browser/IP/session as voted
$_SESSION['voteCompleted'] = TRUE;
logVote();
header("Location: /thanks");
exit();
?>