What are some best practices for updating a value in a database when a link is clicked in PHP?

When a link is clicked in PHP and you want to update a value in a database, you can achieve this by passing the necessary information through the link URL and then processing it in the PHP script that the link points to. This can be done by including parameters in the link URL and then using those parameters to update the database value upon clicking the link.

// Assuming the link URL is like: <a href="update.php?id=123">Update</a>

// update.php
$id = $_GET['id']; // Get the ID parameter from the URL

// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=your_database', 'username', 'password');

// Update the value in the database
$stmt = $pdo->prepare("UPDATE your_table SET your_column = :value WHERE id = :id");
$stmt->execute(array(':value' => 'new_value', ':id' => $id));