2012-04-30 29 views
0

我正在爲我的媒體課進行網頁測驗,但是,我遇到了麻煩。在/var/www/html/horvati2-results.php在線all_my_variables 65注意與PHP相關的警告

注意:當我提交我的測驗,我收到的通知是說:

注意:未定義的變量未定義的變量: CURRENT_TIMESTAMP在/var/www/html/horvati2-results.php上線69

說明:未定義變量:SERVER在/var/www/html/horvati2-results.php線70上

這我的PHP部分看起來像這樣:

$csv_filehandle = fopen("/var/www/html/data/quiz.csv",'a'); 
    fputcsv($csv_filehandle,array($summer,$spring,$fall,$winter)); 
    fclose ($csv_filehandle); 

    $visit_id = uniqid('',TRUE); 

    $json_filehandle = fopen("/var/www/html/data/$visit_id.json",'w'); 
    fwrite($json_filehandle,json_encode($all_my_variables)); 
    fclose($json_filehandle); 

    $all_my_variables = array(
     'timestamp' => $current_timestamp, 
     'user_ip' => $SERVER['REMOTE_ADDR'], 
     'summer' => $summer, 
     'spring' => $spring, 
     'fall' => $fall, 
     'winter' => $winter, 
    ); 


    $current_hour = date_default_timezone_set("America/Chicago"); 
    $current_timestamp = date(DATE_RFC822); 

我將不勝感激一些幫助!

+0

再次看看你的代碼,你做的都是倒退!首先嚐試使用這些變量,然後定義它們是什麼?! – bfavaretto

+0

對不起,我是編程新手!感謝您的迴應,幫助了很多! – user1364717

+0

[PHP:「Notice:Undefined variable」和「Notice:Undefined index」]的可能重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – mario

回答

1

$current_timestamp不存在;不要嘗試使用它。

$SERVER是錯字;它應該是$_SERVER

+0

謝謝!我應該使用什麼變量來包含時間戳呢?我一直在試圖查看它,但我仍然不確定。 – user1364717

0

在聲明之前(2行後面),您正在使用變量:$all_my_variables

嘗試把該線之上:

$json_filehandle = fopen("/var/www/html/data/$visit_id.json",'w'); 
1

警告是這一行:

fwrite($json_filehandle,json_encode($all_my_variables)); 
            ^^^^^^^^^^^^^^^^^ 

這段代碼執行點,all_my_variables尚未確定。