What common mistake is made in the PHP code provided for updating a list of ingredients?

The common mistake in the provided PHP code for updating a list of ingredients is that it does not properly handle the update of each ingredient in the list. To solve this issue, you need to loop through each ingredient in the list and update it individually.

// Connect to the database
$connection = new mysqli("localhost", "username", "password", "dbname");

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

// Update list of ingredients
foreach ($_POST['ingredients'] as $ingredient) {
    $sql = "UPDATE ingredients SET name = '{$ingredient['name']}', quantity = '{$ingredient['quantity']}' WHERE id = {$ingredient['id']}";
    if ($connection->query($sql) !== TRUE) {
        echo "Error updating ingredient: " . $connection->error;
    }
}

// Close connection
$connection->close();