MMCT TEAM
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  ]

Current File : /home2/imyrqtmy/public_html/destinytrafficsolutions/vendor/update_click copy.php
<?php
session_start();

include("inc/config.php");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $project_id = $_POST['project_id'];
    $category_id = $_POST['category_id'];
    $emp_id = $_POST['emp_id'];

    // Fetch last click count for the same project, category, and employee
    $query = "SELECT click_count FROM click_records 
              WHERE project_id = ? AND category_id = ? AND emp_id = ? 
              ORDER BY id DESC LIMIT 1";

    $stmt = $conn->prepare($query);
    $stmt->bind_param("iii", $project_id, $category_id, $emp_id);
    $stmt->execute();
    $result = $stmt->get_result();

    $clickCount = 1; // Default to 1 if no previous record exists
    if ($row = $result->fetch_assoc()) {
        $clickCount = $row['click_count'] + 1; // Increment last count
    }

    // Insert new record with incremented count
    $insertQuery = "INSERT INTO click_records (project_id, category_id, emp_id, click_count, clicked_at) 
                    VALUES (?, ?, ?, ?, NOW())";
    $insertStmt = $conn->prepare($insertQuery);
    $insertStmt->bind_param("iiii", $project_id, $category_id, $emp_id, $clickCount);
    
    if ($insertStmt->execute()) {
        // Return new count and timestamp
        echo json_encode([
            "success" => true,
            "newCount" => $clickCount,
            "lastClicked" => date("Y-m-d H:i:s") // Current timestamp
        ]);
    } else {
        echo json_encode(["success" => false]);
    }

    $stmt->close();
    $insertStmt->close();
    $conn->close();
}
?>
    

MMCT - 2023