Jump to content

Forum message count/last post not updating


Goldeneye

Recommended Posts

So here's the basics:

I've got the following pages

boardlist.php - Shows all the boards with the amount of Topics and Message and when the Last Post was

topiclist.php - Shows all the topics/threads for the corresponding board

messagelist.php - Shows all the posts for the corresponding topic/thread.

post.php - self explanatory

 

So I go to post a new message in an already existing topic, and it gets inserted into the table boardmessages via a mysql_query. Another mysql_query is used to UPDATE the `messages` and `lastpost` fields in `boardtopics`. And another query to UPDATE the same thing, except in the `boards` table. The problem is that neither of these fields are being updated.. the strange thing is that they were before, but seemed to have stopped cooperating for some reason. If it helps, I've been recently working on pagination and BBCode.

 

post.php

<?php
include 'globals.php';
session_start();
connectSQL();
$boardnum = intval($_GET['board']);
$topic = intval($_GET['topic']);

if(!isset($_SESSION['user_id'])) {
header('Location: login.php');
}

else if(isset($_SESSION['user_id'])) {
$namequery = mysql_query("SELECT `pseudonym` FROM `userbase` WHERE `userid`=" . $_SESSION['user_id'] . "");
$namerow = mysql_fetch_array($namequery);
if($_GET['node'] == 'topic'){
	if($_GET['board'] == $boardnum){
		gHeader('Create a Topic');
		if (isset($_POST['createtopic'])) {
			if(empty($_POST['message'])) {
				echo 'You missed a field..<br><br>';
			} else {
				mysql_query("INSERT INTO `boardmessages` (`topicid`, `message`, `from`, `userid`, `deleted`, `ip`, `time`) VALUES ('`topicid`+1', '" . $_POST['message'] . "', '" . $namerow['pseudonym'] . "', '" . $_SESSION['user_id'] . "', 0, '" . $_SERVER['REMOTE_ADDR'] . "', '" . time() . "')");
				mysql_query("INSERT INTO `boardtopics` (`topicid`, `title`, `creator`, `lastpost`, `created`, `userid`, `board`, `pinned`, `closed`, `archived`, `favorites`, `messages`) VALUES ('`topicid`+1', '" . $_POST['title'] . "', '" . $namerow['pseudonym'] . "', '" . time() . "', '" . time() . "', '" . $_SESSION['user_id'] . "', '" . $boardnum . "', 0, 0, 0, 0, 1)");
				mysql_query("UPDATE `boards` SET `messages`=`messages`+1, `topics`=`topics`+1, `lastpost`=" . time() . " WHERE `boardnum`=" . $boardnum . "");
				echo 'T.Hanks for posting! <a href="topiclist.php?board=' . $boardnum . '">Return</a> to the board.<br><br>';
			}
		}

		if (!isset($_POST['createtopic'])){
			echo '<ul class="subnavul"><li class="subnavli"><a href="boardlist.php">Board List</a></li>';
			echo '<li class="subnavli"><a href="topiclist.php?board=' . $boardnum . '" target="_blank"><b>Topic List</b></a></li>';
			echo '</ul>';
			echo '<form action="?node=topic&board=' . $boardnum . '" method="POST">';
			echo 'Title:<br><input type="type" name="title" class="textfieldlong"><br><br>';
			echo 'Message:<br><textarea rows="5" name="message" class="inputbox"></textarea><br>';
			echo '<input type="hidden" name="topid">';
			echo '<input type="submit" value="Create Topic" name="createtopic"  class="button">';
			echo '</form>';
		}
		gFooter();
	}
}

if($_GET['node'] == 'message'){
	if($_GET['board'] == $boardnum){
		if($_GET['topic'] == $topic){
			gHeader('Post a Message: ' . $row2['title']);
			if (isset($_POST['postmessage'])) {
				if(empty($_POST['message'])) {
					echo 'You forgot to post your message.<br><br>';
				} else {
					mysql_query("INSERT INTO `boardmessages` (`topicid`, `message`, `from`, `userid`, `deleted`, `ip`, `time`) VALUES ('" . $topic . "', '" . formatText($_POST['message']) . "', '" . $namerow['pseudonym'] . "', '" . $_SESSION['user_id'] . "', 0, '" . $_SERVER['REMOTE_ADDR'] . "', '" . time() . "')");
					mysql_query("UPDATE `boardtopics` SET `messages`=`messages` + 1, `lastpost`=" . time() . " WHERE `topicid`=" . $topic . " AND `boardnum`=" . $boardnum . "");
					mysql_query("UPDATE `boards` SET `messages`=`messages` + 1 WHERE `boardnum`=" . $boardnum . "");
					echo 'T.Hanks for posting! <a href="messagelist.php?board=' . $boardnum . '&topic=' . $topic . '">View</a> your message.<br><br>';
				}
			}

			if (!isset($_POST['postmessage'])){
				echo '<ul class="subnavul"><li class="subnavli"><a href="boardlist.php">Board List</a></li>';
				echo '<li class="subnavli"><a href="topiclist.php?board=' . $boardnum . '">Topic List</a></li>';
				echo '<li class="subnavli"><a href="messagelist.php?board=' . $boardnum . '&topic=' . $topic . '" target="_blank"><b>Message List</b></a></li>';}
				echo '</ul>';
				// echo 'Post a message in <a href="messagelist.php?board=' . $boardnum . '&topic=' . $topic . '">' . $row['title'] . '</a><br><br>';
				echo '<form action="?node=message&board=' . $boardnum . '&topic=' . $topic . '" method="POST">';
				echo 'Message:<br><input type="hidden" name="topicid">';
				echo '<textarea rows="5" name="message" class="inputbox"></textarea><br>';
				echo '<input type="submit" value="Post Message" name="postmessage"  class="button">';
				echo '</form>';
			}
			gFooter();
		}
	}
}

else
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.