How can the mysql_rows_affected() function be utilized to ensure successful deletion of data in PHP?

To ensure successful deletion of data in PHP using the mysql_rows_affected() function, you can check the number of rows affected after executing a DELETE query. If the function returns a value greater than 0, it indicates that the deletion was successful.

// Execute DELETE query
$query = "DELETE FROM table_name WHERE condition";
$result = mysqli_query($connection, $query);

// Check if deletion was successful
if(mysqli_affected_rows($connection) > 0) {
    echo "Data deleted successfully.";
} else {
    echo "Failed to delete data.";
}