0

While editing a mysql database row, I normally like to check if the action was successful before I redirect my user. Normally I use the following:

$result = mysqli_query($connection, $queryu);
if (mysqli_affected_rows($connection) == 1) {
    // Success
    redirect_to("local_federations.php?local={$local_id}");
} else {
    // Fail
    echo "<p>Failed to edit the Local Federation</p>";
    echo $queryu;
    echo "<p>" . mysqli_error($connection) . "</p>";
}

The problem is, sometimes the user don't change anything on the data, and click "Save Changes" anyways. On this case, the mysqli_affected_rows return 0 (I guess it does) and then I receive the error part of my IF statement, because no rows were affected.

This is all done through an edit button next to a customer name that leads to edit the customer information through an html form.

Would you suggest a better approach for this, making it so it ignores in case no changes were made? Or a way it update the data regardless were any fields were changed?

4

0 回答 0