-
Notifications
You must be signed in to change notification settings - Fork 0
/
like_comment.php
34 lines (34 loc) · 1.05 KB
/
like_comment.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
<?php
include 'conn.php';
include 'desk.php';
if (!isset($_POST['comment_cred'])) die("<invalid_input>");
global $conn;
global $config;
$cid = $_POST['comment_cred'];
$root_query = $conn->query("SELECT * FROM post_comments WHERE id = $cid;");
if ($root_query) {
if ($root_query->num_rows > 0) {
$r = $root_query->fetch_assoc();
$cl = json_decode($r['comment_likes']);
// * Check if already liked, if true, dislike
if (in_array($config['id'], $cl)) {
// ! Dislike
if (($key = array_search($config['id'], $cl)) !== false) {
unset($cl[$key]);
}
} else {
// ? Like
$cl[] = $config['id'];
}
// * Update
// echo gettype(json_encode($cl));
$update_database = $conn->query("UPDATE post_comments SET comment_likes = '" . json_encode($cl) . "' WHERE id = $cid;");
if ($update_database) {
echo '<success>';
} else {
echo '<query_error>';
}
}
} else {
echo '<query_error>';
}