duannian7116 2017-04-26 19:23
浏览 37
已采纳

使用PHP将日期数据插入Mysql表

I am reading the date from android app and send it (As string) to PHP web service to insert the time to MySQL database and save it in string fields but this is not happening.The time format is DD-MM-YYYY like that 25-04-2017, Do I need to convert the date to another format. Here is my PHP code:

<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
{
       require "init.php";

       creat_Student();
}
function creat_Student()
{
    global $con;  
    $user=$_POST["user_id"];
    $car=$_POST["car_id"];
    $dating=$_POST["dating"];
   ;     
    $query="Insert Into items (user_id,car_id,dating) values ('$user','$car','$dating');";
    if(mysqli_query($con,$query))
    echo $con->insert_id;
    else
      echo "Error";   
     mysqli_close($con);
}
?> 

enter image description here

  • 写回答

1条回答 默认 最新

  • doushi7761 2017-04-26 19:37
    关注

    Depending on your database column schema, generally you can string to time $dating then format as YYYY-MM-DD H:i:s or YYYY-MM-DD

    DATETIME in DB Column

    $dating = date('Y-m-d H:i:s',strototime($dating));
    

    OR

    DATE in DB Column

    $dating = date('Y-m-d',strototime($dating));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教