What is the significance of using single quotes around the date variable in the SQL query?

Using single quotes around the date variable in an SQL query is important because it ensures that the date is treated as a string literal in the query. This is necessary to prevent SQL injection attacks and to ensure that the date is properly formatted for the query. Without the single quotes, the query may not work correctly or could be vulnerable to malicious input.

// Assuming $date is the date variable
$date = "2022-01-01";
$sql = "SELECT * FROM table WHERE date_column = '$date'";
$result = mysqli_query($conn, $sql);