-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlike.php
More file actions
23 lines (23 loc) · 721 Bytes
/
like.php
File metadata and controls
23 lines (23 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
session_start();
$postid = $_POST['postid'];
$userid = $_SESSION['id'];
$conn = mysqli_connect('localhost', 'root', '', 'maksitwitter');
if (!$conn) {
die('Connection failed: ' . mysqli_connect_error());
}
$liked = mysqli_query($conn, "SELECT * FROM post_likes WHERE post_id = '$postid' AND user_id = '$userid'");
if ($liked && mysqli_num_rows($liked) > 0) {
echo 'liked';
exit;
}
$query = "UPDATE posts SET likes = likes + 1 WHERE id = '$postid'";
$query2 = "INSERT INTO post_likes (post_id, user_id) VALUES ('$postid', '$userid')";
mysqli_query($conn, $query2);
if (mysqli_query($conn, $query)) {
mysqli_close($conn);
echo 'success';
} else {
echo 'Error: ' . mysqli_error($conn);
}
?>