FPDF:日历选择日期不生成报告数据

时间:2016-11-06 13:32:54

标签: php jquery mysql datepicker fpdf

Jquery日期选择器选择日期不过滤fpdf报告的数据。 (我在下面添加了相关代码。)

datepicker js

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

表单HTML

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

datepicker HTML

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

按钮提交

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

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.discount, S.amount, S.date
                 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 S.date BETWEEN $date.'00:00:00' AND $date.'23:59:59'"); 

$pdf->Cell(25,6,$date,'B',0,'L',0);

当我调试代码时,会出现以下错误。

“Errormessage:您的SQL语法中有错误;请查看与您的MySQL服务器版本对应的手册,以便在'00:00:00'和'。'23:59:59''附近使用正确的语法在第4行“

感谢您的帮助以解决此问题。

1 个答案:

答案 0 :(得分:0)

我已经找到了问题,现在它完美无缺。我从包装提交按钮中删除了<a>,但它确实有效。

编辑后的代码如下:

<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>
                    </label>
                    <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"/>
                    </div>
                    </label></td>
              </tr></form>