How can radio buttons in PHP forms be effectively utilized for updating values in a MySQL database?

Radio buttons in PHP forms can be effectively utilized for updating values in a MySQL database by assigning each radio button a specific value corresponding to the data that needs to be updated in the database. When the form is submitted, the selected radio button value can be retrieved using PHP and used to update the corresponding database record.

<?php
// Assuming a form with radio buttons for selecting a status (e.g. Active or Inactive)
// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

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

if(isset($_POST['submit'])){
    $status = $_POST['status']; // Get the selected radio button value

    // Update database record based on the selected status
    $sql = "UPDATE table_name SET status = '$status' WHERE id = 1"; // Assuming id 1 is the record to be updated
    if ($mysqli->query($sql) === TRUE) {
        echo "Record updated successfully";
    } else {
        echo "Error updating record: " . $mysqli->error;
    }
}

$mysqli->close();
?>

<form method="post">
    <input type="radio" name="status" value="Active"> Active
    <input type="radio" name="status" value="Inactive"> Inactive
    <input type="submit" name="submit" value="Update">
</form>