2011-06-17 153 views
0

這可能是一個n00b的問題,但我不能爲我的生活弄清楚我搞砸了什麼。我以前有過類似的問題,但我認爲我更多地修復了它而不是設計,我真的很想知道我實際上做了什麼錯誤。神祕500錯誤

如果我在pastebin中運行代碼,我得到一個500錯誤。但是,如果我將display_wine函數註釋掉,它會非常好地運行。如果我運行調試器,它會突出顯示關閉的php標籤。我已經檢查並進行了雙重檢查,以確保我沒有任何其他的括號或分號。任何幫助將不勝感激!

<?php 

class simpleCMS { 

    var $host; 
    var $username; 
    var $password; 
    var $table; 
    var $id; 


    public function display_wine_list() { 
    $q = "SELECT * FROM whino ORDER BY created DESC LIMIT 3"; 
    $r = mysql_query($q); 

    if ($r !== false && mysql_num_rows($r) > 0) { 
     while ($a = mysql_fetch_assoc($r)) { 
     $id = $a['id']; 
     $name = stripslashes($a['name']); 
     $created = $a['created']; 
     $type = $a['type']; 

     /** 
     $evalt = "require_once '../generator/qrlib.php';"; 
     eval($evalt); 
     QRcode::png('http://qr.htbx.net/simplecms/mob_display.php?id='.$id, '../generator/temp/'.$id.'.png'); 
     **/ 

     $entry_display .= <<<ENTRY_DISPLAY 

    <div class="post"> 
     <h2> 
      $name 
     </h2> 
     <p>$created</p> 
     <p>$type</p> 

    </div> 

ENTRY_DISPLAY; 
     } 
    } else { 
     $entry_display = <<<ENTRY_DISPLAY 

    <h2> This Page Is Under Construction </h2> 
    <p> 
     No entries have been made on this page. 
     Please check back soon, or click the 
     link below to add an entry! 
    </p> 

ENTRY_DISPLAY; 
    } 
    $entry_display .= <<<ADMIN_OPTION 

    <p class="admin_link"> 
     <a href="{$_SERVER['PHP_SELF']}?admin=1">Add a New Entry</a> 
    </p> 

ADMIN_OPTION; 

    return $entry_display; 
    } 

    public function display_admin() { 
    return <<<ADMIN_FORM 

    <form action="{$_SERVER['PHP_SELF']}" method="post"> 

     <label for="name">Name:</label><br /> 
     <input name="name" id="name" type="text" maxlength="75" /> 
     <div class="clear"></div> 

     <label for="type">Type:</label><br /> 
     <input name="type" id="type" type="text" maxlength="100" /> 
     <div class="clear"></div> 

     <label for="notes">Notes:</label><br /> 
     <textarea name="notes" id="notes"></textarea> 
     <div class="clear"></div> 

     <input type="submit" value="Create This Entry!" /> 
    </form> 

    <br /> 

    <a href="display.php">Back to Home</a> 

ADMIN_FORM; 
    } 

    public function write($p) { 
    if ($_POST['name']) 
     $name = mysql_real_escape_string($_POST['name']); 
    if ($_POST['type']) 
     $type = mysql_real_escape_string($_POST['type']); 
    if ($_POST['grapes']) 
     $grapes = mysql_real_escape_string($_POST['grapes']); 
    if ($_POST['notes']) 
     $notes = mysql_real_escape_string($_POST['notes']); 
    if ($name && $type && $grapes && $notes) { 
     $created = date ("Y-m-d H:i:s", $phptime); 
     $sql = "INSERT INTO whino VALUES('','$name','$type','$grapes', '$notes')"; 
     return mysql_query($sql); 
    } else { 
     return false; 
    } 
} 

    public function connect() { 
    mysql_connect($this->host,$this->username,$this->password) or die("Could not connect. " . mysql_error()); 
    mysql_select_db($this->table) or die("Could not select database. " . mysql_error()); 

    return $this->buildDB(); 
    } 

    private function buildDB() { 
    $sql = <<<MySQL_QUERY 
CREATE TABLE IF NOT EXISTS whino (
id   INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
name  VARCHAR(75), 
notes  TEXT, 
created  DATE, 
type  VARCHAR(100), 
grapes  VARCHAR(75) 
) 
MySQL_QUERY; 

    return mysql_query($sql); 
    } 

public function display_wine($id) { 
    $q = "SELECT * FROM whino WHERE id = $id"; 
    $r = mysql_query($q); 

    if ($r !== false && mysql_num_rows($r) > 0) { 
     while ($a = mysql_fetch_assoc($r)) { 
      $id = $a['id']; 
     $name = stripslashes($a['name']); 
     $created = $a['created']; 
     $type = $a['type']; 

     $entry_display .= <<<ENTRY_DISPLAY 

      <div class="post"> 
       <h2> 
        $name 
       </h2> 
       <p>$created</p> 
       <p>$type</p> 

      </div> 

     ENTRY_DISPLAY; 
     } 
    } else { 
     $entry_display = <<<ENTRY_DISPLAY 

     <h2> This Page Is Under Construction </h2> 
     <p> 
     No entries have been made on this page. 
     Please check back soon, or click the 
     link below to add an entry! 
     </p> 

     ENTRY_DISPLAY; 
    } 
    $entry_display .= <<<ADMIN_OPTION 

    <p class="admin_link"> 
    <a href="{$_SERVER['PHP_SELF']}?admin=1">Edit</a> 
    </p> 

    ADMIN_OPTION; 

    return $entry_display; 
    } 


} 

?> 
+0

該代碼沒有聲明一個類。你應該檢查你的apache錯誤日誌,以便進一步瞭解發生的錯誤。 – Alp

回答

3

您的HEREDOC syntax是不正確的。

$entry_display .= <<<ADMIN_OPTION 

    <p class="admin_link"> 
    <a href="{$_SERVER['PHP_SELF']}?admin=1">Edit</a> 
    </p> 

    ADMIN_OPTION; 

    return $entry_display; 

請參閱ADMIN_OPTION;線是怎麼縮進? HEREDOC的必須在下一行的開頭,因爲這樣的:

$entry_display .= <<<ADMIN_OPTION 

    <p class="admin_link"> 
    <a href="{$_SERVER['PHP_SELF']}?admin=1">Edit</a> 
    </p> 

ADMIN_OPTION; 

    return $entry_display; 
+0

修正HEREDOC後的證明:http://codepad.org/yktbQPVz –

+0

並修復HEREDOC之前:http://codepad.org/sn6mGsu4 –

+0

感謝您花時間解釋它。這很明顯,我沒有真正理解HEREDOC語法,但我想我現在明白了。 –

0

這個問題似乎是你縮進關閉標籤用於定界符分配。不管代碼中發生了什麼,ENTRY_DISPLAY;(等等)都需要一直留在第1列。

+0

我想這是一個愚蠢的問題,但這是非常有用的知道。謝謝! –

+0

@ sh1ps:不是一個愚蠢的問題(至少不是*第一次* :-)。當從命令行運行時,錯誤是'Parse error:syntax error,unexpected in $ end in test.php on line 182'。那麼,這個文件只有* 181行,所以我立即知道這是某種失敗的結束報價或某事。一個體面的語法着色編輯器可以用來捕捉這些類型的東西。 –