<?
include("../../panel/inc/config.php");
$ip = $_SERVER['REMOTE_ADDR'];
// Insert the log
$insert = "INSERT INTO logs (log, ip, date) VALUES ('{$log}', '{$ip}', '{$date}')";
mysql_query($insert) or die("MySQL Error - Could not insert reviews");
$date = date("d/m/y - h:ia");
$insertLog = "INSERT INTO `logs` ( `log` , `ip`, `date` ) VALUES ('viewed test page', '$date')";
mysql_query($insertLog) or die('MySQL Error - Could not insert a log.');
?>
基本上当有人查看此页面时,我希望它插入到数据库中,但它不会插入。我收到插入日志的错误。
有什么想法吗?
我的数据库是
答案 0 :(得分:3)
$insertLog = "INSERT INTO `logs` ( `log` , `ip`, `date` ) VALUES ('viewed test page', '$date')";
此处缺少一个列值。您在上面的查询中有三列但有两个值。您似乎在上述查询中错过了ip值。
你应该这样试试:
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($ip)){
// Insert the log
$insert = "INSERT INTO logs (log, ip, date) VALUES ('{$log}', '{$ip}', '{$date}')";
mysql_query($insert) or die('MySQL Error - ' . mysql_error() );
$date = date("d/m/y - h:ia");
$insertLog = "INSERT INTO `logs` ( `log` , `ip`, `date` ) VALUES ('viewed test page','$ip' '$date')";
mysql_query($insertLog) or die('MySQL Error - ' . mysql_error() );
}