Server IP : 162.214.80.37 / Your IP : 216.73.216.83 Web Server : Apache System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : imyrqtmy ( 2189) PHP Version : 8.2.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home2/imyrqtmy/public_html/destinytrafficsolutions/vendor/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php session_start(); include("inc/config.php"); error_reporting(E_ALL); ini_set('display_errors', 1); if ($_SERVER["REQUEST_METHOD"] == "POST") { $emp_id = $_POST['emp_id'] ?? null; $project_id = $_POST['project_id'] ?? null; $category_id = $_POST['category_id'] ?? null; if (!$emp_id || !$project_id || !$category_id) { echo json_encode(["success" => false, "message" => "Missing parameters"]); exit; } date_default_timezone_set("Asia/Kolkata"); // Set timezone $current_time = date("H:i"); // Get the current hour and minute $current_date = date("Y-m-d"); // Step 1: Check if there is an existing record for this minute $checkQuery = "SELECT id, click_count FROM click_records WHERE emp_id = ? AND project_id = ? AND category_id = ? AND start_time = ? AND clicked_at = ?"; $stmt = $conn->prepare($checkQuery); $stmt->bind_param("iiiss", $emp_id, $project_id, $category_id, $current_time, $current_date); $stmt->execute(); $result = $stmt->get_result(); if ($row = $result->fetch_assoc()) { // Step 2: If record exists, update click count $updateQuery = "UPDATE click_records SET click_count = click_count + 1 WHERE id = ?"; $updateStmt = $conn->prepare($updateQuery); $updateStmt->bind_param("i", $row['id']); $updateStmt->execute(); } else { // Step 3: If no record exists, insert a new row $insertQuery = "INSERT INTO click_records (emp_id, project_id, category_id, click_count, start_time, clicked_at) VALUES (?, ?, ?, 1, ?, ?)"; $insertStmt = $conn->prepare($insertQuery); $insertStmt->bind_param("iiiss", $emp_id, $project_id, $category_id, $current_time, $current_date); $insertStmt->execute(); } // Step 4: Get the updated count $newCountQuery = "SELECT click_count FROM click_records WHERE emp_id = ? AND project_id = ? AND category_id = ? AND start_time = ? AND clicked_at = ?"; $stmt = $conn->prepare($newCountQuery); $stmt->bind_param("iiiss", $emp_id, $project_id, $category_id, $current_time, $current_date); $stmt->execute(); $result = $stmt->get_result(); $newCount = 0; if ($row = $result->fetch_assoc()) { $newCount = $row['click_count']; } echo json_encode(["success" => true, "newCount" => $newCount]); } else { echo json_encode(["success" => false, "message" => "Invalid request"]); } ?>