dongyi0210 2017-04-17 08:06
浏览 19
已采纳

在mysql中更新日期

I have a calendar and i want to insert selected date into mysql database using javascript and php but I'm getting 0000-00-00 in my database row

function monthClick(e) {
clickedDays += 1;
$(e).toggleClass("clicked");
startDateIndex = parseInt($(e).attr('id').split('-')[1]);
startDate = new Date(currentYear, currentMonth, startDateIndex);
id = 160;
var urlU = "id=" + id + "&dateC=" + startDate;
$.ajax({
    url : "http://localhost/dateC.php",
    type : "GET",
    cache : false,
    data : urlU,
    success : function(response) {
        alert(response);
    }

});
}

and here is my php file :

    <?php
    $servername = "localhost";
     $username = "root";
$password = "";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
 $id=$_GET['id'];
 $dateDebutC=$_GET['dateDebutC'];
// Check connection²M
if ($conn->connect_error) {
   die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE normal  SET dateC ='$dateC' WHERE id='$id'";
if ($conn->query($sql)) {
       echo 'DB Update successful';
   }
   else {
       echo 'DB Update failed';
   }
$conn->close();
?>
  • 写回答

2条回答 默认 最新

  • dongyang7152 2017-04-17 08:42
    关注

    mysql requires "YY-MM-DD" fromat. Convert your date in "2017-04-17" format before saving into database table, it will work fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况