-
Notifications
You must be signed in to change notification settings - Fork 1
/
likes.php
68 lines (45 loc) · 1.33 KB
/
likes.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
session_start();
include 'db.php';
$page = $_GET["page"];
$post_id = $_GET["post_id"];
$likes = $_GET["likes"];
$date = date("Y-m-d H:i:s");
$true = "1";
$false = "0";
$sql2 = $db->query("SELECT * FROM `likes` where `post_id` = '$post_id' and `likers`='$username'");
// echo $sql2->rowCount();
$row = $sql2->fetchAll(PDO::FETCH_OBJ);
// echo $likes;
$c= $row[0]->{"liked"};
// echo $c;
if($sql2->rowCount()==0)
{
// echo "HEY";
$sql = $db->query("INSERT INTO `likes` (`post_id`,`likers`,`date`,`liked`) VALUES('$post_id','$username','$date','$true')");
// $likes +=1;
$likes+=1;
}
else if($c===$true && $sql2->rowCount()==1)
{
$sql1 = $db->query("UPDATE `likes` set `liked` ='$false' where `post_id` = '$post_id' and `likers`='$username'");
$likes-=1;
}
else if($sql2->rowCount()==1 && $c===$false)
{
$true= "1";
$sql1 = $db->query("UPDATE `likes` set `liked` ='$true' where `post_id` = '$post_id' and `likers`='$username'");
$likes +=1;
}
// else if($sql2->rowCount()==0 && $c===$true)
// {
// $sql = $db->query("UPDATE `likes` set `liked` ='$false' where `post_id` = '$post_id' and `likers`='$username'");
// $likes -=1;
// }
$sql1 = $db->query("UPDATE `posts` SET `likes` = $likes
WHERE `post_id` = '$post_id'");
if($sql1)
{
header("location:".$page);
}
?>