What are some common pitfalls when using SQL queries in PHP, especially when retrieving values from checkboxes?

When retrieving values from checkboxes in PHP, a common pitfall is not properly handling the checkboxes that are unchecked. If a checkbox is unchecked, its value is not sent in the form submission, so you need to check for its existence in the $_POST array before using it in your SQL query. One way to solve this issue is to use the isset() function to check if the checkbox value is set in the $_POST array before using it in your query.

// Check if the checkbox value is set in the $_POST array
if(isset($_POST['checkbox_name'])) {
    $checkbox_value = $_POST['checkbox_name'];
    // Use the checkbox value in your SQL query
    $sql = "SELECT * FROM table WHERE column = '$checkbox_value'";
    // Execute the query
    $result = mysqli_query($conn, $sql);
} else {
    // Checkbox was unchecked, handle accordingly
}