Hello PHP Help,
line 46 echo works fine.
// echo "<div>" . $date-> format('D Y-m-d') . "</div>";
I am trying to insert these values into the database.
error that I am geting is this:
also, i will incllude the structure of the fields.
I searched for a solution, and I tried many things.
Mostly trying to enter that $date as integer, date and string. no luck so far.
It is time to ask for help.
here is my php.
<!DOCTYPE html>
<html>
<body>
<?php include "includes/db.php"; ?>
<?php
/**
* @begin string A date/time string that can be accepted by the DateTime constructor.
* @end string A date/time string that can be accepted by the DateTime constructor.
* @interval string An interval specification that can be accepted by the DateInterval constructor.
* Defaults to P1D
*
* @return array Array of DateTime objects for the specified date range.
*/
function dateRange($begin, $end, $interval = null)
{
$begin = new DateTime($begin);
$end = new DateTime($end);
// Because DatePeriod does not include the last date specified.
$end = $end->modify('+1 day');
$interval = new DateInterval($interval ? $interval : 'P1D');
return iterator_to_array(new DatePeriod($begin, $interval, $end));
}
$dates = dateRange('2019-09-18', '2020-05-13');
//$weekends = array_filter($dates, function ($date) {
// $day = $date->format("N");
// return $day === '6' || $day === '7';
//});
//foreach ($weekends as $date) {
// echo $date->format("D Y-m-d") . "\n";
//}
$wednesdays = array_filter($dates, function ($date) {
return $date->format("N") === '3';
});
foreach ($wednesdays as $date) {
$query = "INSERT INTO wednesdays (wednesday)";
$query.= "VALUES ('$date')";
// echo "<div>" . $date-> format('D Y-m-d') . "</div>";
$date_query = mysqli_query($connection, $query);
if(!$date_query) {
die("Query Failed!" . mysql_error($connection) . ' ' . mysqli_errno($connection));
}
}
while ($row = mysqli_fetch_array($select_date_query)){
echo $db_wed = $row['wednesday'];
}
?>
</body>
</html>
TY