0

I'm having this error

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '00:00:00 AND 2013-08-01 23:59:59 ORDER BY date' at line 1

With this query

$start_date = date("Y-m-d ") . "00:00:00";
$end_date =  date("Y-m-d ") . "23:59:59";

$result = mysqli_query($con,"SELECT * FROM taxi WHERE del IS NULL AND date BETWEEN " . $start_date . " AND " . $end_date . " ORDER BY date");

And I have no clue about what it could be as I tried the query in phpMyAdmin and it works fine. Anyone can understand why?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mark
  • 645
  • 2
  • 9
  • 27

1 Answers1

2

try putting single quotes around the dates:

  $result = mysqli_query($con,"SELECT * FROM taxi WHERE del IS NULL 
AND date BETWEEN '" . $start_date . "' AND '" . $end_date . "' ORDER BY date");

Also consider using prepared statements to avoid quotes all together. http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

Aris
  • 4,643
  • 1
  • 41
  • 38
  • In addition he needs to be checking always for any mysql errors. If he did he would have seen the exact error and troubleshoot himself.. – Ron May 02 '20 at 22:40