How can one efficiently update a value in a table in PHP to track survey participation?

To efficiently update a value in a table in PHP to track survey participation, you can use SQL queries to update the value in the database based on the user's response. You can identify the user by their unique identifier, such as their user ID or email address, and then update the corresponding column in the table to reflect their participation status.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "survey_db";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Update survey participation status
$user_id = 123; // User's unique identifier
$participation_status = 1; // 1 for participated, 0 for not participated

$sql = "UPDATE survey_participation SET participation_status = $participation_status WHERE user_id = $user_id";

if ($conn->query($sql) === TRUE) {
    echo "Survey participation status updated successfully";
} else {
    echo "Error updating survey participation status: " . $conn->error;
}

$conn->close();
?>