OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
thumbsUp
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
06/17/2025 10:17:24 AM
rwxrwxr-x
📄
handler.php
1.72 KB
05/19/2025 10:07:19 AM
rw-rw-r--
Editing: handler.php
Close
<?php include 'db_connect.php'; include 'function.php'; if ($_SERVER["REQUEST_METHOD"] == "POST") { $articleId = $_POST['articleId']; $gUserId = $_POST['userId']; $response = ['status' => 'error', 'message' => 'An error occurred.']; if ($_POST['action'] == "removeLike") { $sql = "DELETE FROM reader_thumbs_up WHERE articleId = ? AND userId = ?"; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("ii", $articleId, $gUserId); $stmt->execute(); if ($stmt->affected_rows > 0) { $response['status'] = 'success'; $response['message'] = 'Like removed'; } $stmt->close(); } } if ($_POST['action'] == "addLike") { $sql = "INSERT INTO reader_thumbs_up (articleId, userId) VALUES (?, ?)"; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("ii", $articleId, $gUserId); if ($stmt->execute()) { $response['status'] = 'success'; $response['message'] = 'Like added'; } $stmt->close(); } } // Get the updated like count $countSql = "SELECT COUNT(*) AS like_count FROM reader_thumbs_up WHERE articleId = ?"; $countStmt = $mysqli->prepare($countSql); $countStmt->bind_param("i", $articleId); $countStmt->execute(); $result = $countStmt->get_result(); $likeCount = $result->fetch_assoc()['like_count']; $countStmt->close(); $response['newLikeCount'] = $likeCount; // Return the response as JSON header('Content-Type: application/json'); echo json_encode($response); exit(); } ?>