the entire source (excluding static info such as <head>,<title>, etc)
PHP Code:
<div id="leftcontent">
<?php
//News articles start
$news = mysql_query("SELECT * FROM `news` ORDER BY `date` DESC LIMIT 10");
while($article = mysql_fetch_array($news)) {
$articlePosted = $article['date'];
$datePosted = date("F jS, Y", strtotime($articlePosted));
if (empty($_GET['id'])) {
echo '<div class="box3">';
echo '<article><header><h2>'.$article['article_name']. '</h2></header>';
echo '<p>' .$article['summary']. '</p>';
echo '<p>' .$datePosted. '</p>';
echo "<a class='special' href='/news?id={$article['id']}'>Read More...</a></article></div>";
} else if ($_GET['id'] == $article['id']) {
echo '<section><article><header><h1 class="centered"><b><u>'.$article['article_name']. '</u></b></h1></header>';
echo '<p>' .$article['news']. '</p>';
echo '<footer><p>' .$datePosted. '</p></footer></section>';
echo '<section><h1 class="centered">Comments</h1></article>';
//Comments start
$getComments = mysql_query("SELECT * FROM `comments` WHERE `category` = 'news' AND `subcategory` = '$article[id]' ORDER BY `date` DESC LIMIT 20");
while($comments = mysql_fetch_array($getComments)) {
echo "<br />";
echo "<div class='box'>";
if ($comments['reply_to'] > 0) {
$get_comment = mysql_query("SELECT * FROM `comments` WHERE `id` = $comments[reply_to]");
while($r_comment = mysql_fetch_array($get_comment)) {
echo "<i><p>Originally posted by " .$r_comment[username]. '</p></i>';
echo "<i><p> " .$r_comment[comment]. '</p></i>';
echo "<i><p> " .Agotime($r_comment[date]). '</p></i>';
echo "<hr />";
}
}
echo "<p>" .$comments[username]. '</p>';
echo "<p>" .$comments[comment]. '</p>';
echo "<p>" .Agotime($comments[date]). '</p>';
echo "<a class='special' href=\"/news?id={$article['id']}&reply={$comments['id']}\"> Reply</a>";
//Replies start
if ($_GET['reply'] == $comments['id']) {
echo "
<form action=\"/news?id={$article['id']}\" method='POST'>
<input class='field' type='text' name='name' placeholder='Name' required='true' />
<br />
<textarea class='field' name='comment' rows='2' cols='55' required='true'></textarea>
<input type='hidden' name='submitted' value='1' />
<input type='hidden' name='reply' value=\"{$comments['id']}\" />
<input class='specialbutton' type='submit' name='submit' value='Post Comment' />
</form>";
}
echo "<br />
</div>";
//Replies end
}
echo "
<br />
<div class='box'>
<form action=\"/news?id={$article['id']}\" method='POST'>
<input class='field' type='text' name='name' placeholder='Name' required='true' />
<br />
<textarea class='field' name='comment' rows='2' cols='55' required='true'></textarea>
<input class='specialbutton' type='submit' name='submit' value='Post Comment' />
<input type='hidden' name='submitted' value='1' />
</form>
</div>
</section>";
//Comments end
if ($_POST['submitted'] == 1) {
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
$_POST['name'] = stripslashes($_POST['name']);
$_POST['comment'] = stripslashes($_POST['comment']);
$_POST['reply'] = stripslashes($_POST['reply']);
}
$username = mysql_real_escape_string($_POST['name']);
$comment = mysql_real_escape_string($_POST['comment']);
$category = 'news';
$subcategory = $article['id'];
$reply = mysql_real_escape_string($_POST['reply']);
if (empty($username)) {
echo "<p>Name is a required field</p>";
exit();
}
if (empty($comment)) {
echo "<p>Comment is a required field</p>";
exit();
}
$sql = "INSERT INTO `comments` (`username`, `comment`, `date`, `category`, `subcategory`, `reply_to`) VALUES ('$username','$comment', NOW(), '$category', '$subcategory', '$reply')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
}
}
//News articles end
}
?>
</div>
Edit: After updating error reporting, got this error: Notice: Undefined index: submitted in /home1/elitis/public_html/news/index.php on line 98.But 'submitted' has been defined...