How can error handling and debugging techniques be used effectively in PHP to troubleshoot issues with data insertion into MySQL databases?

When troubleshooting data insertion issues into MySQL databases in PHP, error handling and debugging techniques can be used effectively by checking for errors after executing the query and displaying relevant error messages to identify the problem. This can help pinpoint issues such as incorrect data types, missing values, or database connection problems.

// Perform data insertion into MySQL database
$query = "INSERT INTO table_name (column1, column2) VALUES ('$value1', '$value2')";

if(mysqli_query($conn, $query)) {
    echo "Data inserted successfully!";
} else {
    echo "Error: " . $query . "<br>" . mysqli_error($conn);
}