How can PHP be used to handle form data editing and saving in a web application?

To handle form data editing and saving in a web application using PHP, you can create a form that allows users to input data, submit the form to a PHP script that processes the data, and then update the database with the edited information. The PHP script should validate the input data, sanitize it to prevent SQL injection attacks, and then update the database accordingly.

<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Get form data
    $editedData = $_POST['edited_data'];
    
    // Validate and sanitize the input data
    $editedData = htmlspecialchars($editedData);
    
    // Update the database with the edited data
    // $dbConnection is assumed to be the database connection object
    $query = "UPDATE table_name SET column_name = '$editedData' WHERE id = 1";
    $result = mysqli_query($dbConnection, $query);
    
    if ($result) {
        echo "Data updated successfully";
    } else {
        echo "Error updating data";
    }
}
?>