Are there any best practices for incrementing or decrementing the current record in a table with a button click in PHP?

When incrementing or decrementing a value in a database table with a button click in PHP, it is important to first retrieve the current value from the database, then increment or decrement it as needed, and finally update the record in the database with the new value.

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

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

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

// Retrieve current value from the database
$sql = "SELECT value FROM your_table WHERE id = 1";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$currentValue = $row['value'];

// Increment or decrement the current value
$newValue = $currentValue + 1; // or $currentValue - 1;

// Update the record in the database with the new value
$sql = "UPDATE your_table SET value = $newValue WHERE id = 1";
if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

// Close the connection
$conn->close();
?>