douzai3399 2016-08-23 11:04
浏览 152
已采纳

MySql使用html日期输入选择datetime和datetime

I am using MySqli for a MySql server. I am setting up a form in which the user can enter a date using the date input type in a html form:

<div class="ElHolder">
    <form action="productionOutput.php" method="get">
        <input type="date" name="packHistDate" required>
        <input type="submit">
    </form>
</div>

I am then using php to get the date entered and am trying to use it in my sql query. I set $packHistDate = $_GET["packHistDate"] earlier in my code.

        $sql = "SELECT 
                    PRODUCTS.ProductId,
                    PRODUCTS.Name,
                    DATE(PACKING_QUEUE.DatePackFinished) AS \"DateFinished\",
                    PACKING_QUEUE.Packets,
                    PACKING_QUEUE.SizeCode,
                    PACKING_QUEUE.RunSize,
                    BATCHES.BatchId
                FROM PACKING_QUEUE
                    JOIN BATCHES ON BATCHES.BatchId = PACKING_QUEUE.BatchId
                    JOIN PRODUCTS ON PRODUCTS.ProductId = BATCHES.ProductId
                WHERE PACKING_QUEUE.Status = 6 AND PACKING_QUEUE.DatePackFinished BETWEEN ".$packHistDate." AND NOW()
                ORDER BY PACKING_QUEUE.DatePackFinished DESC";
        $result = $conn->query($sql);

        if (!$result) {
            printf("Errormessage: %s
", $conn->error);
        }

PACKING_QUEUE.DatePackFinished is DATETIME and I think that is where the error arises from. However I don't get any error message the code executes but all dates get returned.

I have tried using DATE() to convert them all into dates but that still doesn't work.

Any help is greatly appriciated

UPDATE: adding in single quotes around the ".$datePackFinished." so it was like '".$datePackFinished."' fixed it!

  • 写回答

2条回答 默认 最新

  • dongyounai6281 2016-08-23 20:45
    关注

    Adding in single quotes around the ".$datePackFinished." so it was like '".$datePackFinished."' fixed it!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘