I've been stuck on the same question for a while. Although I'm sure this question should exist somewhere, none of the answers I researched and tried works which is strange.
Here's my code:
if(isset($_POST['date'])){
$date=$_POST['date'];
echo $date; //outputs 2015-04-09
$date = date("Y-m-d", strtotime($date)); //Dropped quotation marks. before it was '$date'
$res = mysqli_query($cxn, "SELECT *
FROM Reservations;
WHERE ResDate=$date);")
or die ("Couldn't execute query.");
while($row = mysqli_fetch_assoc($res)){
extract($row);
echo "Reservation Number: $ResNo<br>Member ID: $MNo<br>VIN: $VIN<br>Reservation Date: $ResDate<br>Reserved Pick-Up Time: $ResTime<br>Pick-Up Address: $PickUpAddress<br>";
echo "________________________________________<br>";
}
}
The problem is at WHERE ResDate=$date
. I'm trying to make $date into DATE type in MySQL. Here are some other ways I tried (I might missed a few)
WHERE ResDate=STR_TO_DATE('$date', '%m-%d-%Y')
(also tried $date without ' ')
WHERE ResDate='$date'
(also tried $date without ' ')
WHERE ResDate=CONVERT(DATETIME, '$date')
(also tried $date without ' ')
WHERE ResDate=CAST('$date' AS DATE)
(also tried $date without ' ')
For all the above variations, I got "Couldn't execute query." I'm running out of ideas.. any help? Thanks in advance.
UPDATE: Here's some code from the page before:
$dates = mysqli_query($cxn, "SELECT ResDate
FROM Reservations")
or die ("Couldn't execute query.");
$dateArray = array();
array_push($dateArray, '<option>' . "Choose Date" . '</option>');
while($row = mysqli_fetch_assoc($dates)){
extract($row);
array_push($dateArray, '<option>' . "$ResDate" . '</option>');
}
So $ResDate from the database should be transferred to the next page, I think..