I want to ask you what I do wrong with insert date to table. I wanto to insert only date choosen by user, but it save me only 0000-00-00 00:00:00. Where I have a mistake?
MySQL Table
CREATE TABLE IF NOT EXISTS `transakcia` (
`id` int(6) NOT NULL AUTO_INCREMENT,
`description` varchar(100) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
)
function Add - add new row to table
function Add(){
$("#example2 tbody").last().append(
"<tr>"+
"<td></td>"+
"<td><input id='description' type='text' class='form-control'/></td>"+
"<td style='max-width: 250px;'><div class='input-group'><div class='input-group-addon'><i class='fa fa-calendar'></i></div><input id='date' type='date' class='form-control' /></div></td>"+
"<td><img src='./img/save-icon.png' class='btnSave'/><img src='img/delete-icon.png' class='btnDelete'/></td>"+
"</tr>"
);
$(".btnSave").bind("click", Save);
$(".btnDelete").bind("click", Delete);
};
function Save - save new row to DB
function Save(){
var par = $(this).parent().parent();
var tddescription = par.children("td:nth-child(2)");
var tddate = par.children("td:nth-child(3)");
var description = tddescription.children("input[type=text]").val();
var date = tddate.children("input[type=date]").val();
jQuery.post("table_save_ajax.php", {
description:description,
date:date
}, function(data, textStatus){
if(data == 0){
$('#response').html("Successfull!!");
$('td:nth-child(4)').hide();
tddescription.html(tddescription.children("input[type=text]").val());
tddate.html(tddate.children("input[type=date]").val());
}else{
$('#response').html(data);
}
});
};
table_save_ajax.php - php to save date into table
<?php
include("config.php");
$description = $_POST['description'];
$date = $_POST['date'];
$errors = array();
$sql = mysql_query("INSERT INTO transakcia (description, date) VALUES ('$description','$date')");
if(!$sql){
$errors[] = "ERROR INSERT";
}
if(count($errors) == 0){
echo "0";
}else{
foreach($errors as $e){
echo $e . "<br />";
}
}
?>