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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退