Valhalla Legends Forums Archive | Web Development | Help with forum code

AuthorMessageTime
FrozenShadeHello, I have been working on some forums, and i've gotten as far as posting topics, replying to topics,  etc; except  i am having troubles with adding categories. Here is what I have so far if anyone could help it would be great.
   

if($_POST['replyedit'] == 'Edit')
{
	
$p_id = $_POST['p_id'];
	
$body = $_POST['message'];

$sql = "UPDATE forum_posts SET post = '$body' WHERE p_id = '$p_id'";
mysql_query($sql);

$sql = "SELECT t_id FROM forum_posts WHERE p_id = '$p_id'";
$result = mysql_query($sql);
$r=mysql_fetch_array($result);
$t_id=$r["t_id"];


echo
"Post Entered!<br>
<a href='index.php?page=16'>Back to topic list</a><br>
<a href='index.php?page=16&view=$t_id'>View topic</a>"
;

} elseif(
$_GET['replyedit'] != 0)
{
	
$p_id = $_GET['replyedit'];

$sql = "SELECT post FROM forum_posts WHERE p_id = '$p_id'";
$result = mysql_query($sql);
$r=mysql_fetch_array($result);
$body=$r["post"];

echo
"<br><center><table><form method='post' action='index.php?page=16'>
<tr><td class='cap'>Message</td></tr>
<tr><td align='center'>"
;

include(
"BBcode.php");

echo
"<textarea cols='45' rows='20' name='message'>$body</textarea>
<input type='hidden' name='p_id' value='$p_id'>
</td></tr>
<tr><td align='center'><input type='submit' name='replyedit' value='Edit'></td></tr>
</table></form></center>"
;


} elseif(
$_GET['replydel'] != 0)
{
	
$p_id = $_GET['replydel'];

$sql = "DELETE FROM forum_posts WHERE p_id = '$p_id'";
mysql_query($sql);

echo
"Post Deleted!<br>
<a href='index.php?page=16'>Back to Topic List</a>"
;


} elseif(
$_GET['topdel'] != 0)
{
	
$t_id = $_GET['topdel'];

$sql = "DELETE FROM forum_topics WHERE t_id = '$t_id'";
mysql_query($sql);

$sql = "DELETE FROM forum_posts WHERE t_id = '$t_id'";
mysql_query($sql);

echo
"Topic Deleted!<br>
<a href='index.php?page=16'>Back to topic list</a>"
;



} elseif(
$_POST['topic'] == 'Post Topic')
{

	
$subject = $_POST['subject'];
	
$topic = $_POST['body'];

$sql = "INSERT INTO forum_topics(title, started, last_poster, dt, last_post_dt)
VALUES('$subject', '$_SESSION[username]', '$_SESSION[username]', now(), now())"
;
mysql_query($sql);


$sql = "SELECT t_id FROM forum_topics ORDER BY t_id DESC";
$result = mysql_query($sql);
$r=mysql_fetch_array($result);
$t_id=$r["t_id"];


$sql = "INSERT INTO forum_posts(author_name, dt, post, t_id) VALUES('$_SESSION[username]', now(), '$topic', '$t_id')";
mysql_query($sql);




echo
"Topic entered!<br>
<a href='index.php?page=16'>Back to topic list</a><br>
<a href='index.php?page=16&view=$t_id'>View Topic</a>"
;


} elseif(
$_GET['topics'] == 1)
{
	


	
echo
"<br><center><table><form method='post' action='index.php?page=16'>
<tr><td class='cap'>Topic</td></tr>
<tr><td align='left'>
Subject: <input type='text' name='subject'><br><br>"
;

include(
"forumfunctions.php");

echo
"<textarea cols='45' rows='20' name='body'></textarea>
</td></tr>
<tr><td align='center'><input type='submit' name='topic' value='Post Topic'></td></tr>
</table></form></center>"
;

} elseif(
$_POST['reply'] == 'Post Reply')
{
	
$t_id = $_POST['t_id'];
	
$post = $_POST['message'];


$sql = "INSERT INTO forum_posts(author_name, dt, post, t_id) VALUES('$_SESSION[username]', now(), '$post', '$t_id')";
mysql_query($sql);

$sql = "UPDATE forum_topics SET last_poster = '$_SESSION[username]', last_post_dt = now() WHERE t_id = '$t_id'";
mysql_query($sql);

echo
"Message entered!<br>
<a href='index.php?page=16'>Return to to topic list</a><br>
<a href='index.php?page=16&view=$t_id'>View your message</a>"
;



} elseif(
$_GET['reply'] != 0)
{
	
$t_id = $_GET['reply'];

echo
"<br><center><table><form method='post' action='index.php?page=16'>
<tr><td class='cap'>Message</td></tr>
<tr><td align='center'>"
;

include(
"forumfunctions.php");

echo
"<textarea cols='45' rows='20' name='message'></textarea>
<input type='hidden' name='t_id' value='$t_id'>
</td></tr>
<tr><td align='center'><input type='submit' name='reply' value='Post Reply'></td></tr>
</table></form></center>"
;




} elseif(
$_GET['view'] != 0)
{
	
$t_id = $_GET['view'];

$sql = "SELECT title FROM forum_topics WHERE t_id = '$t_id'";
$result = mysql_query($sql);
$r=mysql_fetch_array($result);
$title=$r["title"];


echo
"<br>
<a href='index.php?page=16&reply=$t_id'>Reply</a> | <a href='index.php?page=16'>Back to topic list</a><br>
<center><table border='1' bordercolor='#000000' cellspacing='0' cellpadding='0' width=400>
<tr><td class='cap'>$title"
;

$sql = "SELECT started FROM forum_topics WHERE t_id = '$t_id'";
$result = mysql_query($sql);
$r=mysql_fetcH_array($result);
$started=$r["started"];


	
if(
$_SESSION['level'] >= 9 || $started == $_SESSION['username'])
{
	
echo
"- <a href='index.php?page=16&topdel=$t_id'>Delete</a>";

}

echo
"</td></tr>";

$sql = "SELECT * FROM forum_posts WHERE t_id = '$t_id' ORDER BY p_id ASC";
$result = mysql_query($sql);

	
while(
$r=mysql_fetch_array($result))
{
	
$id=$r["p_id"];
	
$author=$r["author_name"];
	
$dt=$r["dt"];
	
$post=$r["post"];
	

echo
"<tr><td bgcolor='#990000'>$author - $dt";

if(
$_SESSION['level'] >= 9 || $author == $_SESSION['username'])
{
	
echo
"- <a href='index.php?page=16&replyedit=$id'>Edit</a> - <a href='index.php?page=16&replydel=$id'>Delete</a>";

}
	


echo
"</td></tr>

<tr><td>$post</td></tr>"
;

}

echo
"</table></center><br>";

} else {


$sql = "SELECT * FROM forum_topics ORDER BY t_id DESC";
$result = mysql_query($sql);

	
if(
mysql_num_rows($result) == 0)
{
	
echo
"No Topics have been posted. Click <a href='index.php?page=16&topics=1'>here</a> to start a topic";

} else {

echo
"<br>
<a href='index.php?page=16&topics=1'>New topic</a><br>
<center><table border='1' bordercolor='#000000' cellspacing='0' cellpadding='0'>
<tr><td class='cap' align='center'>Title</td>
<td class='cap' align='center'>Topic starter</td>
<td class='cap' align='center'>Last Poster</td></tr>"
;

	
while(
$r=mysql_fetch_array($result))
{
	
$id=$r["t_id"];
	
$title=$r["title"];
	
$starter=$r["started"];
	
$lastposter=$r["last_poster"];
	
$startdate=$r["dt"];
	
$lpdate=$r["last_post_dt"];
	

echo
"<tr><td><a href='index.php?page=16&view=$id'>$title</a></td>
<td>$starter<br>
on $startdate</td>
<td>$lastposter<br>
on $lpdate</td></tr>"
;

}
 
echo
"</table></center>";
}
}
?>


ugly code i know  Tongue but any help would be appreciated. Thanks!
August 26, 2005, 04:46 pm
BlazeUse

[php ]
[/php]
August 26, 2005, 07:35 pm
FrozenShadethere ya go.August 26, 2005, 09:07 pm
R.a.B.B.i.TPost only the part that adds a new category, please.  I don't feel like trying to pick out what it is...August 26, 2005, 09:50 pm
FrozenShadethere isn't one as of yet. my attempts kept messing up, so I came here hoping someone could help me.  EmbarrassedAugust 26, 2005, 09:53 pm
R.a.B.B.i.T-.-;;August 27, 2005, 12:37 am
Topaz^__^August 27, 2005, 05:29 pm