How can PHP be utilized to track user activity on a website for updating database entries?

To track user activity on a website for updating database entries, you can use PHP to capture user actions such as page views, form submissions, clicks, etc. This data can then be stored in a database table to keep a record of user interactions with the website.

// Assuming you have a database connection established

// Capture user activity
$user_id = $_SESSION['user_id']; // Assuming you have a user session
$action = "Page view"; // Example action, can be customized based on user activity
$timestamp = date('Y-m-d H:i:s'); // Current timestamp

// Insert user activity into database
$sql = "INSERT INTO user_activity (user_id, action, timestamp) VALUES ('$user_id', '$action', '$timestamp')";
$result = mysqli_query($conn, $sql);

if($result) {
    echo "User activity tracked successfully.";
} else {
    echo "Error tracking user activity: " . mysqli_error($conn);
}