Hey.
Recently embarked on setting up a PHP blog system using a code provided to me, here at NG, via Mr. Hulse. The login page works fine and, as far as I know, it's all correct. However, when trying to view the main page it retrieves the following error.
Parse error: syntax error, unexpected $end in /home/willjb/public_html/index.php on line 480
Now, the code is long so will have to be spread out over two posts, but, anyone who wants to have a look and give a shot at fixing it is more than welcome. I'm completely stumped on this one.
<?php session_start(); ?>
<?php
$max_items = 10;
$db = mysql_connect ('localhost','USERNM','PASSWRD');
mysql_select_db ('willjb_blog',$db);
function displayNews($all) {
global $db, $max_items;
if ($all == 0) {
$query = "SELECT id, title, newstext," . "DATE_FORMAT(postdate, '%b %e, %Y') as date " . "FROM news ORDER BY id DESC LIMIT $max_items";
} else {
$query = "SELECT id, title, newstext," . "DATE_FORMAT(postdate, '%b %e, %Y') as date " . "FROM news ORDER BY id DESC";
}
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc ($result)) {
echo "<TABLE border=\"0\" width=\"400\" align=\"center\">\n";
$date = $row['date'];
$title = htmlentities ($row['title']);
$news = strip_tags ($row['newstext'], '<a><b><i><u>');
$news = nl2br ($news);
$id = $row['id'];
echo "<TR><TD><p><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id=$id\"<b>$title</b></a> posted on <i>$date</i></p></TD>\n";
echo "\n";
$comment_query = "SELECT count(*) FROM news_comments " . "WHERE news_id={$row['id']}";
$comment_result = mysql_query ($comment_query);
$comment_row = mysql_fetch_row($comment_result);
echo "<TD algin=\"right\"><p><a href=\"{$_SERVER['PHP_SELF']}" . "?action=showcom&id={$row['id']}\">Comments</a> " . "{" . "$comment_row[0]}</p></TD></TR>\n";
echo "</TABLE>\n";
echo "\n";
}
if ($all == 0) {
echo "<br /><center><a href=\"{$_SERVER['PHP_SELF']}" . "?action=all\">View all news</a></center>\n";
}
}
function displayOneItem($id) {
global $db;
$query = "SELECT * FROM news WHERE id=$id";
$result = mysql_query ($query);
if (mysql_num_rows ($result) == 0) {
echo "<center><b>Error!</b></center>\n";
echo "<p>No News Exists for the ID specified. Please try again.</p>\n";
return;
}
$row = mysql_fetch_assoc($result);
echo "<TABLE border=\"0\" width=\"400\" align=\"center\">\n";
$title = htmlentities ($row['title']);
$news = strip_tags ($row['newstext'], '<a><b><i><u>');
$news = nl2br ($news);
echo "<TR><TD align=\"center\"><b><p>$title</p></b></TD></TR>\n";
echo "<tr><td align=\"center\"><p><<<------------------------------------------->>></p></td></tr>\n";
echo "<TR><TD><p>$news</p></TD></TR>\n";
echo "</TABLE>\n";
echo "<BR>\n";
echo "<Center>";
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo "";
}else{
echo "<hr color=\"#666666\" width=\"50%\" />";
echo "→ <b><a href=\"index.php?action=editnews129&id=$id\">Edit News</a></b>
--
<b><a href=\"index.php?action=deletenews129&id=$id\" onClick=\"return confirm('Are you sure you really want to start to try to delete this valuable piece of information that can never be retrieved no matter how hard I trys?')\">Delete News</a></b> ←";
echo "<hr color=\"#666666\" width=\"50%\" />";
}
echo "</center>";
echo '<center><a href="' . $_SERVER[PHP_SELF] . '?action=showcom&id=' . $id . '">Show Comments</a></center>';
}
function displayOneItem_withComments($id) {
global $db;
$query = "SELECT * FROM news WHERE id=$id";
$result = mysql_query ($query);
if (mysql_num_rows ($result) == 0) {
echo "<center><b>Error!</b></center>\n";
echo "<p>No News Exists for the ID specified. Please try again.</p>\n";
return;
}
$row = mysql_fetch_assoc($result);
echo "<TABLE border=\"0\" width=\"400\" align=\"center\">\n";
$title = htmlentities ($row['title']);
$news = strip_tags ($row['newstext'], '<a><b><i><u>');
$news = nl2br ($news);
echo "<TR><TD align=\"center\"><b><p>$title</p></b></TD></TR>\n";
echo "<tr><td align=\"center\"><p><<<------------------------------------------->>></p></td></tr>\n";
echo "<TR><TD><p>$news</p></TD></TR>\n";
echo "</TABLE>\n";
echo "<BR>\n";
echo "<Center>";
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo "";
}else{
echo "<hr color=\"#666666\" width=\"50%\" />";
echo "→ <b><a href=\"index.php?action=editnews129&id=$id\">Edit News</a></b>
--
<b><a href=\"index.php?action=deletenews129&id=$id\" onClick=\"return confirm('Are you sure you really want to start to try to delete this valuable piece of information that can never be retrieved no matter how hard I trys?')\">Delete News</a></b> ←";
echo "<hr color=\"#666666\" width=\"50%\" />";
}
echo "</center>";
displayComments($id);
}
function displayComments($id) {
global $db;
$query = "SELECT * FROM news_comments WHERE news_id=$id";
$result = mysql_query ($query);
echo '<center><a href="' . $_SERVER[PHP_SELF] . '?action=show&id=' . $id . '">Show without Comments</a></center>';
echo "<center><h3>Comments</h3><HR width=\"100%\"></center>\n";
while ($row = mysql_fetch_assoc ($result)) {
echo "<TABLE border=\"0\" width=\"400\" align=\"center\">\n";
$name = htmlentities ($row['name']);
echo "<TR><TD><u>Posted by <b>$name</b></u>";
echo "</TD></TR>\n";
$comment = strip_tags ($row['comment'], '<a><b><i><u>');
$comment = nl2br ($comment);
echo "<TR><TD><p>$comment</p></TD></TR>\n";
echo "<tr><td align=\"left\" valign=\"top\">";
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo "";
}else{
echo "<p>← <a href=\"index.php?action=editcom129&id={$row['id']}\">Edit Comment</a> -- <a href=\"index.php?action=deletecom129&id={$row['id']}\" onClick=\"return confirm('Are you sure you really want to start to try to delete this valuable piece of information that can never be retrieved no matter how hard I trys?')\">Delete Comment</a> →</p>";
}
echo "</tr></td>";
echo "<tr><td><p>====================================================</p></td></tr>\n";
echo "</TABLE>\n";
echo "\n";
function addComment($id) {
global $db;
$query = "INSERT INTO news_comments " . "VALUES('',$id,'{$_POST['name']}'," . "'{$_POST['comment']}')";
mysql_query($query);
echo "Comment entered. Thanks!<BR>\n";
echo "<center><a href=\"{$_SERVER['PHP_SELF']}" . "?action=showcom&id=$id\">Back</a></center>\n";
}
function addnews129($id) {
global $db;
session_start();
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo '<center><h3>Error!</h3></center>You do not have sufficeint permission to view this page.';
}else{
$query = "SELECT * FROM news WHERE id=$id";
$result = mysql_query ($query);
echo "<center><h3>Add News</h3></center>\n";
echo "<div align=\"left\">";
echo "There are 4 types of add-ins allowed to be used. They are: <ul>";
echo "<li><b><b>BOLD</b></b> </li>";
echo "<li><i><i>ITALIC</i></i> </li>";
echo "<li><u><u>UNDERLINED</u></u> </li>";
echo "<li><a href=\"http://www.somesite.com\"><a href=\"http://www.somesite.com\">NAME OF SOMESITE</a></a></li></ul>";
echo "</div>";
echo "<center><FORM action=\"{$_SERVER['PHP_SELF']}" . "?action=addnews\" method=POST>\n";
echo "Title: <input type=\"text\" " . "size=\"30\" name=\"title\"><BR>\n";
echo "<TEXTAREA cols=\"40\" rows=\"15\" " . "name=\"news\"></TEXTAREA><BR>\n";
echo "<input type=\"submit\" name=\"submit\" " . "value=\"Add News\"\n";
echo "</FORM></center>\n";
}
}
function addnews($id) {
global $db;
$title = $_POST['title'];
$newstext = $_POST['news'];
$query = "INSERT INTO news (postdate, title, newstext)" . "VALUES(NOW(), '$title', '$newstext')";
$result = mysql_query($query);
if($result){
echo "<center>News Submitted</center><BR>\n";
echo "<center><a href=\"{$_SERVER['PHP_SELF']}\">Back</a></center>\n";
}else{
echo 'Error! Something\'s wrong with the database or something!<br /><br /><b>';
echo mysql_error();
echo '</b>';
}
}
function editnews129($id) {
global $db;
if(!isset($_SESSION['admin']) && !isset($_SESSION['password'])){
echo '<center><h3>Error!</h3></center>You do not have sufficient permission