doqw89029 2014-07-16 16:09
浏览 29

从生成的行向MySQL插入日期

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 />";
    }
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line