-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_post_vote_check.php
53 lines (45 loc) · 1.35 KB
/
change_post_vote_check.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
<?php
include ('header.php');
if (! $loggedin) {
$_SESSION ['AlertRed'] = "You have to be logged in to do that.";
header ( "location:index.php" );
} else {
$postid = $_POST ['postid'];
// $userid is given
$stmt = $db->prepare ( "SELECT * FROM UpvotesForPosts WHERE PostID=? AND UserID=?" );
$stmt->execute ( array (
$postid,
$userid
) );
$row = $stmt->fetch ( PDO::FETCH_ASSOC );
if (empty ( $row )) {
// add new
$stmt = $db->prepare ( "INSERT INTO UpvotesForPosts (PostID,UserID,CreatedOn,IsDeleted) VALUES (?,?,NOW(),0);" );
$stmt->execute ( array (
$postid,
$userid
) );
} else {
$isdeleted = $row['IsDeleted'];
if($isdeleted == 1)
{
$stmt = $db->prepare ( "UPDATE UpvotesForPosts SET IsDeleted=0 WHERE PostID=? AND UserID=?" );
$stmt->execute ( array (
$postid,
$userid
) );
}
else
{
$stmt = $db->prepare ( "UPDATE UpvotesForPosts SET IsDeleted=1 WHERE PostID=? AND UserID=?" );
$stmt->execute ( array (
$postid,
$userid
) );
}
}
$db = null; // close connection
// $_SESSION['AlertGreen'] = "Successfully upvoted post!!";
header ( "location:show_post.php?post_id=" . $postid );
}
?>