php - FPDF: Report data not generates for calendar selected date



Jquery date picker selected date is not filtering data for fpdf report. (I have added the related codes below.)

datepicker js

$(document).ready(function() {
   $("#datepicker12").datepicker({ dateFormat: 'yy-mm-dd' });
   $("#datepicker12").datepicker("setDate", new Date);

form HTML

<form id="salesReportForm" name="salesReportForm" method="post" action="../reports/dailyreports.php" >

datepicker HTML

<input id="datepicker12"  name="datepicker12" tabindex="6" class="txtbx" /> 

Button submit

<a target="popup" onclick="'../reports/monthlyreports.php','popup','width=1200,height=900'); return false;">
                  <input type="button" name="btnMonthlyReports" id="btnMonthlyReports" value="GENERATE" />

report.php (FPDF)

if(isset($_POST['datepicker12'])){ $date = $_POST['datepicker12'];}

$result=mysqli_query($connection,"SELECT S.sales_id, I.item_name, ST.stock_code, S.qty, S.unit_price,, S.amount,
                 FROM sales S 
                 INNER JOIN items I ON S.item_id=I.item_id 
                 INNER JOIN stock ST ON S.stock_id=ST.stock_id WHERE BETWEEN $date.'00:00:00' AND $date.'23:59:59'"); 


When I debug the code, below error appears.

"Errormessage: 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 .'23:59:59'' at line 4 "

Appreciate your help to resolve this.

1 Answer: 

I have figured out the issue, and now it works perfectly. I removed <a> from wrapping the submit button, and it worked.

Edited code is as below:

<form id="dailysalesReportForm" name="dailysalesReportForm" method="post" action="../reports/dailyreports.php" ><tr>
                <td width="147" height="34"><div align="left">DAILY</div></td>
                  <td width="116"><label>
                    <div align="center">
                      <input id="datepicker12"  name="datepicker12" tabindex="6" class="txtbx" />
                    <div align="center"></div></td>
                  <td width="104"><div align="center"></div></td>
                  <td width="81"><label>
                    <div align="center"> 
                      <input type="submit" name="btnDailyReports" id="btnDailyReports" value="GENERATE"/>