0

I get the DATE variable from the Datepicker Jquery UI and include it as variable in the MYSQL statement. But select does not work with the variable. What reason ?

Below the code

$fromDate = new DateTime($from);
$toDate = new DateTime($to);

$fromDate2 = mysqli_real_escape_string($fromDate);
$toDate2 = mysqli_real_escape_string($toDate);

$sql = mysqli_query($mySqlConnect,"SELECT * FROM 1398_log WHERE date BETWEEN $fromDate2 AND $toDate2 ORDER by id DESC");

This select OK:

$sql = mysqli_query($mySqlConnect,"SELECT * FROM 1398_log WHERE date BETWEEN '2016-03-01 00:00:00' AND  '2016-06-30 23:59:59'ORDER by id DESC");
Sanzeeb Aryal
  • 4,358
  • 3
  • 20
  • 43

1 Answers1

0

You need to provide the date as a string in sql:

$sql = mysqli_query($mySqlConnect,"SELECT * 
FROM 1398_log 
WHERE date BETWEEN '$fromDate2' AND '$toDate2'
ORDER by id DESC");

Watch the '

Psi
  • 6,387
  • 3
  • 16
  • 26