How can you use a button in PHP to end form editing and prevent saving to the database?

To end form editing and prevent saving to the database using a button in PHP, you can set a flag when the button is clicked and check this flag before saving the form data to the database. By doing so, you can control whether the form data should be saved based on the button click event.

<?php
// Check if the button is clicked
if(isset($_POST['end_editing'])){
    // Set a flag to indicate form editing should end
    $endEditing = true;
}

// Save form data to the database only if editing is not ended
if(isset($_POST['submit']) && !$endEditing){
    // Save form data to the database
    // Your database saving code here
}
?>

<form method="post" action="">
    <!-- Your form fields here -->
    
    <button type="submit" name="submit">Save</button>
    <button type="submit" name="end_editing">End Editing</button>
</form>