-3
I am making a system that registers a set of dates via $_POST. I want to insert in the database the range created below via datetime. But when executing appears the above message. How to proceed? The error appears in the $sql statement.
$start = new DateTime($_POST["data1"]); //nova data começo
$end = new DateTime($_POST["data2"]); // final da data
$interval = new DateInterval("P1D"); //intervalo de datas no periodo de um dia
$period = new DatePeriod($start, $interval, $end); //periodo no começo da data, intervalo e final da data
try
{
$connection = new PDO("mysql:host=localhost;dbname=php","root","");
$connection->exec("set_names_utf8");
}
catch(PDOExeption $e)
{
echo "Erro" . $e->getMessage();
}
$sql = "INSERT INTO datas(datas) VALUES('$period->format('d-m-Y')')";
$x = $connection->prepare($sql);
$x->execute();