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!