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

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条)

相关推荐 更多相似问题