This may be a n00b question, but I cannot for the life of me figure out what I'm screwing up. I've had a similar problem before but I think I fixed it more by accident than design, and I'd really like to know what I'm actually doing wrong.
I get a 500 error if I run the code in the pastebin. However, if I comment out the display_wine function it runs perfectly fine. If I run the debugger it just highlights the closing php tag. I've checked and double checked to make sure I didn't have any additional brackets or semicolons. Any help would be greatly appreciated!
<?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:</labe开发者_Go百科l><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;
}
}
?>
Your HEREDOC syntax is not right.
$entry_display .= <<<ADMIN_OPTION
<p class="admin_link">
<a href="{$_SERVER['PHP_SELF']}?admin=1">Edit</a>
</p>
ADMIN_OPTION;
return $entry_display;
See how that ADMIN_OPTION;
line is indented? HEREDOC's have to be at the beginning of the next line, as such:
$entry_display .= <<<ADMIN_OPTION
<p class="admin_link">
<a href="{$_SERVER['PHP_SELF']}?admin=1">Edit</a>
</p>
ADMIN_OPTION;
return $entry_display;
The problem appears to be that you indented the closing label for your heredoc assignments. ENTRY_DISPLAY;
(etc.) needs to be all the way left to column 1, regardless of whatever else is happening in your code.
精彩评论