I'm trying to insert a date into a table on my database. I currently this HTML code to insert the date :
<!DOCTYPE html>
<html>
<body>
<form method="post">
<input type="date" name="date">
<input type="submit" name="submit">
</form>
</body>
</html>
And this PHP code to process the request :
<?php
if(isset($_POST['submit'])) {
$conn = new mysqli(MY_CONNECTION);
$sql = "INSERT INTO my_table (date) VALUES (".$_POST['date'].")";
$result = $conn->query($sql);
if(!$result) {
die("SQL Error : ".$sql."<br>Error : ".$conn->error);
}
}
?>
My table only contains an ID
column and a DATE
column that is a DATE
type.
When I submit my form, SQL executes correctly but when my values are stored in the database the result for DATE
is '0000-00-00'. I didn't change anything in the date format of my database.
I tried with a print_r
on my $_POST
array end it prints out this :
Array ( [date] => 2017-04-04 [sell_Software_1] => Sell )
What am I doing wrong?
Thanks!