-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddLikeToPost.php
More file actions
26 lines (20 loc) · 853 Bytes
/
addLikeToPost.php
File metadata and controls
26 lines (20 loc) · 853 Bytes
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
<?php
include_once 'dbconfig.php';
$conn = mysqli_connect($dbconfig["host"], $dbconfig["user"], $dbconfig["password"], $dbconfig["name"]) or die("Errore: ".mysqli_connect_error());
$post_id = mysqli_real_escape_string($conn, $_GET["id"]);
$user = mysqli_real_escape_string($conn, $_GET["user"]);
$query = "INSERT INTO likes_for_posts(user, post_id) VALUES('$user', $post_id)";
if(mysqli_query($conn, $query)){
$query_1 = "SELECT num_likes FROM posts WHERE id=$post_id";
$res = mysqli_query($conn, $query_1);
if(mysqli_num_rows($res) > 0){
$row = mysqli_fetch_assoc($res);
$js = [
'post_id' => $post_id,
'num_likes' => $row["num_likes"]
];
echo json_encode($js);
}
}
mysqli_close($conn);
?>