dtpyvb1873 2014-10-17 15:47 采纳率: 0%
浏览 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条)

报告相同问题?