dtpyvb1873 2014-10-17 15:47
浏览 145
已采纳

时间戳不起作用

Im trying to know the time and date everytime a new entry is saved in my database. So i set the column as follows:

enter image description here

The problem is that im just geting 0000-00-00 00:00:00 as the date/time:

enter image description here

The code that im using to update the database is:

<?php

$lat = $_GET['lat'];
$lon = $_GET['lon'];
$fecha = $_GET['fecha'];

// Make a MySQL Connection

$db_database = "xxx";
$db_hostname = "xxx";
$db_username = "xxx";
$db_password = "xxx";


$enlace = mysql_connect($db_hostname, $db_username, $db_password);
if (!$enlace) {
    die('No pudo conectarse: ' . mysql_error());
}
echo 'Conectado satisfactoriamente. <br>';
// mysql_close($enlace);


mysql_select_db('xxxxx') or die(mysql_error());


$q = "INSERT INTO `posicion` (`Hora`, `Latitud`, `Longitud`) VALUES 
 ('$fecha', '$lat','$lon')";

//Run Query
$result = mysql_query($q) or die(mysql_error());

echo "Tamos redi";

?>

What can it be ?

Thanks a lot.

  • 写回答

2条回答 默认 最新

  • dougu6815 2014-10-17 16:01
    关注

    Considering the default value for Hora is CURRENT_TIMESTAMP, you can just rely on MySQL to fill it in.

    $q = "INSERT INTO `posicion` (`Hora`, `Latitud`, `Longitud`) VALUES 
     (NULL, '$lat','$lon')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试