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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器