What are the potential pitfalls of using multiple UPDATE queries in PHP for form submissions?

Using multiple UPDATE queries in PHP for form submissions can lead to potential pitfalls such as increased database load, slower performance, and increased chances of data inconsistency if one of the queries fails. To solve this issue, you can use a single UPDATE query with all the necessary updates combined.

// Connect to the database
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Get form data
$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];

// Update the database with a single query
$sql = "UPDATE users SET name='$name', email='$email' WHERE id='$id'";

if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

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