dongzhuo0895 2016-11-30 07:41
浏览 28
已采纳

将日期转换为mysql格式无效

I am trying to insert ClassID, TestID and Deadline into a database table, and it seems that the format of my date is not allowing the INSERT query to work. I've tried converting it with this method but it isn't working. When I run my function, it returns "Data cannot be inserted". When I echo $date in the function it gives: 2016-12-01

My function:

public function createAssignment($theClassID,$dueDate)
{
    $testID = $_SESSION['currentTestID'];

    $date = mysql_real_escape_string($_POST['dueDate']);
    $date = date('Y-m-d', strtotime($date));

    echo $date;

    $sql="INSERT INTO settest (ClassID, TestID, Deadline) VALUES ('$theClassID', '$testID', $date)";
    $result = mysqli_query($this->db,$sql) or die(mysqli_connect_errno()."Data cannot be inserted");
    return $result;
}
  • 写回答

2条回答 默认 最新

  • duangou2046 2016-11-30 07:58
    关注

    My bad. I was entering the same data multiple times, and therefore the composite key was being repeated. Works now

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

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动