Jump to content

Forums


Psycho-Path

Recommended Posts

Ok I have some forums on my site and I would like to customize for it to be most like the leading ones out there (ipb, phpbb, vb, etc.)

So I have the basics setup right now, but I would like to make it so there is:
registration for membership page
member page
login page
bbcode on posting
etc etc

I'm not asking for people to just change my script for me, cause I'm not a freeloader, I like doing work.  But I like getting help as well :)

So here are the files I have so far.

forums.php
[code]<?php
include "connect.php"; //mysql db connection here
print "<link rel='stylesheet' href='style.css' type='text/css'>";
print "<table class='maintable'>";
print "<tr class='headline'><td width=40% class='headline-text'>Topic</td><td width=20% class='headline-text'>Topic Starter</td><td width=15% class='headline-text'>Replies</td><td class='headline-text'>Last replied time</td></tr>";
$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC";
$getthreads2=mysql_query($getthreads) or die("Could not get threads");
while($getthreads3=mysql_fetch_array($getthreads2))
{
$getthreads3[title]=strip_tags($getthreads3[title]);
$getthreads3[author]=strip_tags($getthreads3[author]);
print "<tr class='mainrow'><td><a class='topic' href='index.php?act=topics&id=$getthreads3[postid]'>$getthreads3[title]</a></td><td class='info-text'>$getthreads3[author]</td><td class='info-text'>$getthreads3[numreplies]</td><td class='info-text'>$getthreads3[showtime]<br>&nbsp;Last post by <b>$getthreads3[lastposter]</b></td></tr>";
}
print "</table>";

?> [/code]

post.php
[code]<?php
include "connect.php"; //connection string
print "<link rel='stylesheet' href='style.css' type='text/css'>";
print "<table class='maintables'>";
print "<tr class='headline'><td>Post a message</td></tr>";
print "<tr class='maintables'><td>";
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$yourpost=$_POST['yourpost'];
$subject=$_POST['subject'];
if(strlen($name)<1)
{
print "You did not type in a name."; //no name entered
}
else if(strlen($yourpost)<1)
{
print "You did not type in a post."; //no post entered
}
else if(strlen($subject)<1)
{
print "You did not enter a subject."; //no subject entered
}
else
{
$thedate=date("U"); //get unix timestamp
$displaytime=date("F j, Y, g:i a");
//we now strip HTML injections
$subject=strip_tags($subject);
$name=strip_tags($name);
$yourpost=strip_tags($yourpost);
$insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter) values('$name','$subject','$yourpost','$displaytime','$thedate','$name')";
mysql_query($insertpost) or die("Could not insert post"); //insert post
print "Message posted, go back to <A href='index.php'>Forum</a>.";
}

}
else
{
print "<form action='post.php' method='post'>";
print "Your name:<br>";
print "<input type='text' name='name' size='20'><br>";
print "Subject:<br>";
print "<input type='text' name='subject' size='20'><br>";
print "Your message:<br>";
print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>";
print "<input type='submit' name='submit' value='submit'></form>";

}
print "</td></tr></table>";
?>[/code]

reply.php
[code]<?php
include "connect.php"; //connection string
print "<link rel='stylesheet' href='style.css' type='text/css'>";
print "<table class='maintables'>";
print "<tr class='headline'><td>Reply</td></tr>";
print "<tr class='maintables'><td>";
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$yourpost=$_POST['yourpost'];
$subject=$_POST['subject'];
$id=$_POST['id'];
if(strlen($name)<1)
{
print "You did not type in a name."; //no name entered
}
else if(strlen($yourpost)<1)
{
print "You did not type in a post."; //no post entered
}
else
{
$thedate=date("U"); //get unix timestamp
$displaytime=date("F j, Y, g:i a");
//we now strip HTML injections
$subject=strip_tags($subject);
$name=strip_tags($name);
$yourpost=strip_tags($yourpost);
$insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter,parentid) values('$name','$subject','$yourpost','$displaytime','$thedate','$name','$id')";
mysql_query($insertpost) or die("Could not insert post"); //insert post
$updatepost="Update forumtutorial_posts set numreplies=numreplies+'1', lastposter='$name',showtime='$displaytime', lastrepliedto='$thedate' where postid='$id'";
mysql_query($updatepost) or die("Could not update post");
print "Message posted, go back to <A href='message.php?id=$id'>Message</a>.";
}

}
else
{
$id=$_GET['id'];
print "<form action='reply.php' method='post'>";
print "<input type='hidden' name='id' value='$id'>";
print "Your name:<br>";
print "<input type='text' name='name' size='20'><br>";
print "Your message:<br>";
print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>";
print "<input type='submit' name='submit' value='submit'></form>";

}
print "</td></tr></table>";
?>[/code]

topics.php
[code]<?php
include "connect.php"; //mysql db connection here
$id=$_GET['id'];
print "<link rel='stylesheet' href='style.css' type='text/css'>";
$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC";
$getthreads2=mysql_query($getthreads) or die("Could not get threads");
{
$getthreads3[title]=strip_tags($getthreads3[title]);
$getthreads3[author]=strip_tags($getthreads3[author]);
print "<font class='title-top'>Forums -> Topic</font>";
print "<br />";
}
print "<table class='maintable'>";
print "<tr class='headline'><td width=20%>Author</td><td width=80%>Post</td></tr>";
$gettopic="SELECT * from forumtutorial_posts where postid='$id'";
$gettopic2=mysql_query($gettopic) or die("Could not get topic");
$gettopic3=mysql_fetch_array($gettopic2);
print "<tr class='mainrow'><td valign='top'>$gettopic3[author]</td><td valign='top'>This topic was made on $gettopic3[showtime]<br><hr>";
$message=strip_tags($gettopic3['post']);
$message=nl2br($message);
print "$message<br /><br />";
print "</td></tr>";
$getreplies="SELECT * from forumtutorial_posts where parentid='$id' order by postid desc"; //getting replies
$getreplies2=mysql_query($getreplies) or die("Could not get replies");
while($getreplies3=mysql_fetch_array($getreplies2))
{
print "<tr class='mainrow'><td valign='top'>$getreplies3[author]</td><td valign='top'>Last replied to at $getreplies3[showtime]<br><hr>";
$message=strip_tags($getreplies3['post']);
$message=nl2br($message);
print "$message<br /><br />";
print "</td></tr>";
print "<tr class='mainrow'><td valign='top'><a class='topic' href='index.php?act=post&id=$getthreads3[postid]'>Reply<br>";
print "</td></tr>";
}
print "</table>";
?>[/code]

ok those are all the files I have, could you guys direct me in some tutorials that could give me help or if you could help me on the things I asked for.

Thanks A BUNCH!
Andrew
Link to comment
Share on other sites

You would simply need to create a database table called catigories. This would hold an id and the name of the catigory. Then, in the table that holds the threads make another field called cat_id, this would hold the catigory id for each thread.

To list all threads in catigory 5 for instance you would use a simple query something like...

[code]
SELECT topic FROM threads WHERE cat_id = 5;
[/code]
Link to comment
Share on other sites

For the creation of a new table called catagories would this be ok sql?

[code]CREATE TABLE `forum_cat` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;[/code]

and then for the table that holds the threads

[code]SELECT * FROM `forum_posts` WHERE 1
`cat_id` VARCHAR(250) NOT NULL,
) ENGINE=MyISAM;[/code]

is that correct?
Link to comment
Share on other sites

forum_cat is correct, Im not sure what your doing in the other part though. You need to add the field cat_id to whatever table it is your storing your threads in. So it would be more like....

[code]
ALTER TABLE forum_posts ADD cat_id INT(11);
[/code]
Link to comment
Share on other sites

I think I have made enough threads so I'm just going to post it in here...
I have this register page for users, and the page is blank, I think it's the if statements that are screwing up.

[code="register.php"]<?php
require ("connect.php"); //mysql db connection here
require ("functions.php");

//echo some styles to spice it up...

echo "
<style>
body {
background: 131313;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: FFFFFF;
}
.register_box {
border: 1px solid 323232;
background: 202020;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: FFFFFF;
}
</style>
";

echo "
<font class='title-top'>Register</font>
<br />
";

switch($_GET['action'])
{
case "new":
//--------------------------------------
// [New Registration]
//--------------------------------------
if(!isset($_POST['register']))
{
echo "
<form action='index.php?act=register.php&action=new' method='POST'>
Username: <br />
<input type='text' name='username' class='register_box'>
<br />
Email: <br />
<input type='text' name='email' class='register_box'>
<br />
Password: <br />
<input type='password' name='password' class='register_box'>
<br />
<input type='submit' name='register' value='Register' class='register_box'>
</form>
";
}
elseif(isset($_POST['register']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$activation_code = generateCode(25);

$userq = "SELECT username FROM user_system WHERE username = '$username' LIMIT 1";
$emailq = "SELECT email FROM user_system WHERE email = '$email' LIMIT 1";

//put errors into an array
$errors = array();
if(empty($username))
{
$errors[] = "The username field was blank! <br />";
}
if(mysql_num_rows(mysql_query($userq)) > 0)
{
$errors[] = "The username given is already in use! Please try another one! <br />";
}
if(empty($password))
{
$errors[] = "The password field was blank! <br />";
}
if(empty($email))
{
$errors[] = "The email field was blank! <br />";
}
if(mysql_num_rows(mysql_query($emailq)) > 0)
{
$errors[] = "The email given is already in use! Please try another one! <br />";
}
if(count($errors) > 0)
{
foreach($errors as $err)
{
echo $err;
}
}
else
{
$sqlq = "INSERT INTO user_system (username, password, email, is_activated, activation_code)";
$sqlq .= "VALUES ('$username', '".md5($password)."', '$email', '0', '$activation_code')";
mysql_query($sqlq) or die(mysql_error());
echo "Thanks for registering!
You will recieve an email shortly containing your validation code,
and a link to activate your account!";
mail($email, "New Registration, localhost", "
Thanks for registering at the site.
Here are your login details:

Username: ".$username."
Password: ".$password."

In order to login and gain full access, you must validate your account.

Click here to validate:

http://localhost/test/index.php?act=register.php&action=activate&user=".$username."&code=".$activation_code."

Thanks!
[Webmaster]
");
}
}
break;
}
?> [/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.