2014-04-12 43 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錯誤 –