2014-04-12 42 views
-1
<? 
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.'); 
?> 

基本上当有人浏览这个页面时,我希望它插入到数据库中,但它没有插入。我得到插入日志的错误。没有插入到数据库sql读取错误

任何想法?

我的数据库是

enter image description here

+2

和错误是? – meda

+1

为什么要日期文字? –

+0

@meda'MySQL Error - Could not insert a log.' – TrippedStackers

回答

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()); 
    } 

通知:所有mysql_*功能已被弃用。您应该移至PDOmysqli

+0

仍然给我MySQL错误 - 无法插入日志。 'error – TrippedStackers

+0

尝试我更新的答案 –

+1

@TrippedStackers使用'die('MySQL Error - '。mysql_error())'显示真正的MySQL错误 –