How can the code be modified to handle the success or failure of the database query?

To handle the success or failure of the database query, you can use conditional statements to check if the query was executed successfully or not. You can use functions like mysqli_query() to execute the query and then check the result to determine if it was successful. If the query was successful, you can proceed with further actions, and if it failed, you can handle the error accordingly.

// Execute the database query
$result = mysqli_query($conn, $sql);

// Check if the query was successful
if ($result) {
    // Query was successful, proceed with further actions
    // For example, fetch data from the result set
    while ($row = mysqli_fetch_assoc($result)) {
        // Process the data
    }
} else {
    // Query failed, handle the error
    echo "Error: " . mysqli_error($conn);
}

// Close the database connection
mysqli_close($conn);