时间戳不工作

问题描述:

我试图知道每次在我的数据库中保存一个新条目的时间和日期。所以我设置列如下:时间戳不工作

enter image description here

的问题是,我只是歌厅0000-00-00 00:00:00的日期/时间:

enter image description here

的代码,即时通讯使用更新数据库是:

<?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"; 

?> 

它可能是什么?

非常感谢。

+0

怎么样。你插入数据? – 2014-10-17 15:51:31

+0

从服务器调用一个.php文件: http://www.example.com/update.php?lat=x&lon=y – 2014-10-17 15:52:56

+0

您能告诉我们您的PHP脚本是否插入数据 – 2014-10-17 15:53:31

考虑Hora的默认值是CURRENT_TIMESTAMP,你可以只依靠MySQL来填补它在

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

它的工作!非常感谢 – 2014-10-17 16:03:42

+0

不客气! – 2014-10-17 16:03:54

尝试:

alter table <INSERT TABLENAME> modify <Hora> TIMESTAMP DEFAULT CURRENT_TIMESTAMP 
     ON UPDATE CURRENT_TIMESTAMP; 

和reffer: http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html