PHP 不将日期时间插入 mysql 表

标签 php mysql sql datetime

我已经搜索并尝试了几种不同的方法,但我总是得到 0000-00-00 00:00:00

这是我的页面:

<?php

require_once "../../maincore.php";

require_once THEMES."templates/header.php";



$earnedpoints = false; 

$account = $_GET['account']; 

$account = mysql_real_escape_string($account); 



if ($account == "") { 

    echo 'Enter an account name!'; 

    exit(); 

} 



$ip = $_SERVER['REMOTE_ADDR']; 

$time = time(); 



$query = mysql_query("SELECT *, SUM(`times`) as amount FROM votingrecords WHERE account='$account' OR ip='$ip'"); 

$lasttime = mysql_fetch_array($query); 

$amount = $lasttime['amount']; 

$insertnew = false;     

if ($amount == "") { 

    $insertnew = true; 

} 

$timecalc = $time - $lasttime['date'];



if (!$insertnew) { 

    if ($timecalc < 43200) {  

    require_once THEMES."templates/header.php";

    add_to_title(" - Vote");

    opentable("Error");

    echo "<table class='tbl-border' width='100%' cellspacing='1' cellpadding='5'><td class='tbl2'>";

        echo ' Hello '. $account .' you have already voted with this account ('. $account .') or IP ('. $ip .') in the last 12 hours!'; 

        echo ' Last voted on: '. date('Y-m-d H:i:s', $lasttime['date']) .''; 

        echo '<html>'; 

        echo '<head>'; 

    echo '<meta HTTP-EQUIV="REFRESH" content="10; url=\vote.php?account=' . $_GET['account'] . '">'; 

        echo '</head>'; 

        echo '<body>'; 

        echo '<br /><br /><center>You will be redirected to the main website in 10 seconds.</center>'; 

        echo '</body>'; 

        echo '</html>'; 

    echo "</td></table>";

    closetable();

    require_once THEMES."templates/footer.php";

        exit(); 

    } else {                 

        $update = mysql_query("UPDATE votingrecords SET account='$account', date='NOW()', times=times+1 WHERE ip='$ip'");

            if (!$update) { 

                $message  = 'Invalid query: ' . mysql_error() . "\n"; 

                $message .= 'Whole query: ' . $update; 

                die($message); 

            } else { 

                $earnedpoints = true; 

            } 

        } 

} else { 

    $success = mysql_query("INSERT INTO votingrecords (`account`, `ip`, `date`, `times`) VALUES ('$account', '$ip', 'NOW()', 1)"); 

    if (!$success) { 

            $message  = 'Invalid query: ' . mysql_error() . "\n"; 

            $message .= 'Whole query: ' . $success; 

            die($message); 

    } else { 

        $earnedpoints = true; 

    } 

}

if ($earnedpoints) { 

    $points = mysql_query("UPDATE user SET votingpoints = votingpoints + 1 WHERE login='$account'");                

    if (!$points) { 



            $message  = 'Invalid query: ' . mysql_error() . "\n"; 

            $message .= 'Whole query: ' . $query; 

            die($message); 

    } 

    mysql_close(); 

    echo '<html>'; 

    echo '<head>'; 

    echo '<meta HTTP-EQUIV="REFRESH" content="0; url=vote here">'; 

    echo '</head>'; 

    echo '</html>'; 

} else { 

    echo 'There was an error processing your request.'; 

    exit(); 

} 



require_once THEMES."templates/footer.php";

?>

这解决了我不插入日期的问题,现在可以正常工作了!!多谢! 我认为这会解决我的问题,因为它不跟踪用户何时投票,因此他们只能每 12 小时投票一次。它仍然让人们一遍又一遍地投票 >。<

有没有办法解决这个问题? Lmao.. 仍然需要一些帮助

最佳答案

不要将 NOW() 放在单引号内...

关于PHP 不将日期时间插入 mysql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22052439/

相关文章:

java - MySQL jdbc 数据库连接器错误故障排除

sql - SQL查询表是否存在

c# - 动态获取照片?

页面更改时 PHP connection_aborted() 不起作用

mysql - SQL:格式化电话号码(插入空格)

php - 语法错误 : COLUMN isn't in GROUP BY (SQL, Laravel)

php - 从 MySQL 数据库中删除一行

sql - 从 Go 中的 SQL 查询中获取计数和结果

php - Laravel 如何将用户输入与数据库中的数据进行比较

php - Laravel - 检查帐户何时创建