dtjxhf595733 2013-08-05 08:03
浏览 35
已采纳

PHP和SQL自动插入日期和时间[重复]

This question already has an answer here:

I am trying to auto insert date and time into my SQL database when a form is submitted from a php page

$sql="INSERT INTO tracker_msisdn_trace (msisdn, avis_name, date, colour, driver, 
driver_id, notes)
VALUES 
('$_POST[msisdn]','$_POST[avis_name]','$_POST[date]','$_POST[colour]','$_POST[driver]','$_POST
[driver_id]','$_POST[notes]')";

This is the code I use for Manual inserting data.

To auto insert the day I have tried the following

 $date = date("Y-m-d") 
 $_POST[".$date."]

I am not getting the date and time inserted into the SQL it shows 0000-00-00

This is my SQL table

Name Type Collation Attributes Null Default Extra

4 date date No None

Assistance would be appreciated

</div>
  • 写回答

1条回答 默认 最新

  • dongxiaoshe0737 2013-08-05 08:04
    关注

    You can do like this :

    $date = date("Y-m-d") 
    $_POST['date'] = $date
    

    Otherway :

    $sql="INSERT INTO tracker_msisdn_trace (msisdn, avis_name, date, colour, driver, 
    driver_id, notes)
    VALUES 
    ('$_POST[msisdn]','$_POST[avis_name]','". $date ."','$_POST[colour]','$_POST[driver]','$_POST
    [driver_id]','$_POST[notes]')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM