Can someone please tell me why my php function isn’t inserting into Mysql?
[php]<?php
// post data
$jobname = $_POST[‘jobname’];
$begin = $_POST[‘begin’];
$end = $_POST[‘end’];
$customer = $_POST[‘customer’];
$zip = $_POST[‘zip’];
$city = $_POST[‘city’];
$workdesc = $_POST[‘workdesc’];
$phone = $_POST[‘phone’];
$email = $_POST[‘email’];
// date loop
function dates() {
$begin = $_POST[‘begin’];
$end = $_POST[‘end’];
$begin2 = new DateTime( $begin );
$end2 = new DateTime( $end );
$end2 = $end2->modify( ‘+1 day’ );
$interval = new DateInterval(‘P1M1D’);
$daterange = new DatePeriod($begin2, $interval ,$end2);
foreach($daterange as $date){
echo $date->format(“m/d/Y”) . “
”;
}
}
// mysql connection
$servername = “localhost”;
$username = “root”;
$password = “”;
$dbname = “test”;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = “INSERT INTO data (promiseddate)
VALUES (’”.dates()."’)";
if ($conn->query($sql) === TRUE) {
echo “New record created successfully”;
} else {
echo "Error: " . $sql . “
” . $conn->error;
}
$conn->close();
?>[/php]
It should insert multiple dates from the date interval function. I’m lost!!