0

hi everyone,
i am working on forums and i found something very useful to those who develop forums
i attached files and may it will help somebody. i included one style sheet which is in txt format change that into .css
thanku

Attachments
<?php



$db = mysql_connect("localhost", "root", "1234") or die("Could not connect.");

if(!$db) 

	die("no db");

if(!mysql_select_db("forums",$db))

 	die("No database selected.");



?>
<?php 

include "conn.php"; //mysql db connection here



$goku="SELECT * from tbl_categories where  parentid=0";

$goku2=mysql_query($goku) or die("Could not get threads");

$goku3=mysql_fetch_array($goku2);

echo $cat="SELECT * from tbl_categories where parentid=".$goku3['c_id'];

$cat1=mysql_query($cat) or die("Could not get threads");

$cats=mysql_fetch_array($cat1);
?>
<link rel='stylesheet' href='style.css' type='text/css'>
<A href='post.php'>New Topic</a><br>
<table class='maintable'>
 <td><?=$goku3['c_name'];?></td>
<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>

<? 
$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto asc";

$getthreads2=mysql_query($getthreads) or die("Could not get threads");

$getthreads3=mysql_fetch_array($getthreads2);
  $getthreads3['title']=strip_tags($getthreads3['title']);

  $getthreads3['author']=strip_tags($getthreads3['author']);
  
   $cat="SELECT * from tbl_categories where parentid=".$goku3['c_id'];

$cat1=mysql_query($cat) or die("Could not get threads");

  while($scat=mysql_fetch_array($cat1))

{
  
  ?>

  <tr class='mainrow'><td><A href='message.php?id=<?=$scat['c_id']?>'><?=$scat['c_name'];?></a></td><td><?=$getthreads3['author'];?></td><td><?=$getthreads3['numreplies'];?></td><td><?=$getthreads3['showtime'];?><br>Last post by <b><?=$getthreads3['lastposter'];?></b></td></tr>
<? 
}
?>
</table>
<?php 

include "conn.php"; //mysql db connection here

$id=$_GET['id'];
?>

<link rel='stylesheet' href='style.css' type='text/css'>

<A href='index.php'>Back to main forum</a>-<A href='post.php'>New Topic</a>-<A href='reply.php?id=$id'>Reply<br>

<table class='maintable'>

<tr class='headline'><td width=20%>Author</td><td width=80%>Post</td></tr>
<? 

echo $gettopic="SELECT * from forumtutorial_posts where cat_id='$id'";

$gettopic2=mysql_query($gettopic) or die("Could not get topic");

while($gettopic3=mysql_fetch_array($gettopic2))
{
?>

<tr class='mainrow'><td valign='top'><?=$gettopic3['author'];?></td>
<td vakign='top'>
<?=$gettopic3['post'];?><br><hr>
Posted Time: <?=$gettopic3['showtime'];?></td></tr>
<tr bgcolor="#003366" >
  <td valign='top'></td>
  <td vakign='top'></td>
</tr><?
 }?>
</table>
<?php

include("conn.php"); //connection string
?>
<link rel='stylesheet' href='style.css' type='text/css'>

<table class='maintables'>

<tr class='headline'><td>Post a message</td></tr>
<tr class='maintables'><td>
<? 
if(isset($_POST['submit']))

{
                 
  echo "hiiiiiiiiiiii";
   $title=$_POST['title'];

   $yourpost=$_POST['yourpost'];
   
   $selcategory=$_POST['selcategory'];

   

   if(strlen($title)<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($selcategory)<1)

   {

      print "You did not selected category."; //no subject entered

   }

   else

   {
       
				
				
      $thedate=date("U"); //get unix timestamp

      $displaytime=date("F j, Y, g:i a");

      //we now strip HTML injections

      $selcategory=strip_tags($selcategory);

      $title=strip_tags($title);

      $yourpost=strip_tags($yourpost); 
	  
			 	
      $insertpost="INSERT INTO forumtutorial_posts(cat_id,title,post,showtime,realtime) values('$selcategory','$title','$yourpost','$displaytime','$thedate')";

      mysql_query($insertpost) or die("Could not insert post"); //insert post
       
      print "Message posted, go back to <A href='index.php'>Forum</a>.";
   }
}

?>
<?
 $qry4="SELECT * FROM tbl_categories WHERE parentid=0";
					$res3=mysql_query($qry4) or die(mysql_error());
				$res4=mysql_fetch_array($res3);
 $qry5="SELECT * FROM `tbl_categories` WHERE parentid='".$res4['c_id']."'";
				$res5=mysql_query($qry5) or die(mysql_error());
$num5=mysql_num_rows($res5);
?>
 <form action='post.php' method='post'>
   select sub topic title 
   :<br>
<input name='title' type='text' id="title" size='20'>
<br>
  under topic <br>
  <select name="selcategory" class="box2" id="selcategory">
                         <option value="">------Selectcategory-------</option>
						 <?  
				if($num5>0)
				{
				while($row5=mysql_fetch_array($res5))
				{
					?>
                          
                        <option value="<?=$row5['c_id']?>" selected="selected" <? if ((isset($_GET['c_id']))&&($row5['c_id']==$category))?><? {?>selected<? }?>>//
                           <?=$row5['c_name']?>
         </option>
                         <?
				  }
				  }
			 ?>
   </select>
<br>

   Your message:<br>

  <textarea name='yourpost' rows='5' cols='40'></textarea><br>

 <input type='submit' name='submit' value='submit'></form>


<? 

?>
</td></tr></table>
<?php

include "conn.php"; //connection string
?>

<link rel='stylesheet' href='style.css' type='text/css'>
<table class='maintables'>

<tr class='headline'><td>Reply</td></tr>

<tr class='maintables'><td>
<? 
if(isset($_POST['submit']))

{

   $name=$_POST['name'];

   $yourpost=$_POST['yourpost'];


   $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
      $name=strip_tags($name);

      $yourpost=strip_tags($yourpost); 

      $insertpost="INSERT INTO forumtutorial_posts(author,post,showtime,realtime,lastposter,parentid) values('$name','$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'];
   ?>

   <form action='reply.php' method='post'>

   <input type='hidden' name='id' value='$id'>

   Your name:<br>

  <input type='text' name='name' size='20'><br>

   Your message:<br>

   <textarea name='yourpost' rows='5' cols='40'></textarea><br>

<input type='submit' name='submit' value='submit'></form>

<? 

}
?>
</td></tr></table>
<style>

body {

a:link, a:visited, a:active { text-decoration: none}

font-family:Verdana, Sans-serif;

color; #000000;

font-size: 12px

}

input,textarea, select,{

	color : #000000;

	font: normal 12px;

	border-collapse: collapse; border: 1px solid #000000;

}

.maintable {border: 0px ; width: 100%; padding: 0px; background-color: #FFFFFF} /*main table for forum*/

.regrow {font-family: Verdana,Sans-serif; color: #000000; font-weight: bold; background-color: #FFFFFF;font-size: 12px;} /*registration row, mainly here for symetry*/

.headline {font-family: Verdana,Sans-serif;font-weight: bold;color: #FFFFFF;background-color: #003366;font-size: 11px;} /*headline row, the first row that says forum name, topics, posts and such*/

.forumrow {font-family: Verdana,Sans-serif; color: #000000;background-color: #F2F2F2;font-size: 12px;} /*color of the forum rows*/

.mainrow a:link, a:visited,  a:active { text-decoration: none;}

.mainrow {font-family: Verdana,Sans-serif; color: #000000;background-color: #F2F2F2;font-size: 12px; a:link, a:visited, a:active { text-decoration: none}} /*color of the forum rows*/

.maintables{background-color: #FFFFFF; width: 95%; padding: 0px; border: 1px solid; cellspacing: no} /*main table for forum*/
</style>
4
Contributors
11
Replies
12
Views
9 Years
Discussion Span
Last Post by mexabet
0

hi everyone,
i am working on forums and i found something very useful to those who develop forums
i attached files and may it will help somebody. i included one style sheet which is in txt format change that into .css
thanku

Hi Praveen,

Is it possible to provide the database also.
Thanks in advance.

0

yeh, sure my friend

Attachments
Database: `forums`
-- 

-- --------------------------------------------------------

-- 
-- Table structure for table `forumtutorial_posts`
-- 

CREATE TABLE `forumtutorial_posts` (
  `postid` bigint(20) NOT NULL auto_increment,
  `author` varchar(255) NOT NULL default '',
  `title` varchar(255) NOT NULL default '',
  `post` mediumtext NOT NULL,
  `showtime` varchar(255) NOT NULL default '',
  `realtime` bigint(20) NOT NULL default '0',
  `lastposter` varchar(255) NOT NULL default '',
  `numreplies` bigint(20) NOT NULL default '0',
  `parentid` bigint(20) NOT NULL default '0',
  `lastrepliedto` bigint(20) NOT NULL default '0',
  `cat_id` int(100) NOT NULL default '0',
  PRIMARY KEY  (`postid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ;

-- 
-- Dumping data for table `forumtutorial_posts`
-- 

INSERT INTO `forumtutorial_posts` (`postid`, `author`, `title`, `post`, `showtime`, `realtime`, `lastposter`, `numreplies`, `parentid`, `lastrepliedto`, `cat_id`) VALUES (24, 'arya', 'forums', 'hi its very good right', 'July 14, 2008, 11:04 am', 1216013593, 'rocky', 1, 0, 1216013645, 0),
(25, 'rocky', '', 'you are right', 'July 14, 2008, 11:04 am', 1216013645, 'rocky', 0, 24, 0, 0);
0

Okay, assuming I call this database table file databse_backup.sql, how then can I reference it in those PHP files?

yeh, sure my friend

0

Please, tell me the detailed steps to achieve this. Should the database login be inside conn.php?

hi mexabet,
you need to import that file into your database

0

hi mexabet,
you will have import option in your database and in conn.php

<?
mysql_connect("localhost","username","password");
mysql_select_db("databasename");
?>

and u need to include conn.php in every page where u use sql quieries

0

Hi.
I think you posted one of the dumped table of the MySQL, where are the other tables like tbl_categories.

thanks

0

yeh my fault sorry, actually i was working on that forums and made some modifications according to my requirements.now, the database file i have attached will work with files i attached now if any doubts u can ask me.

Attachments
<?php



$db = mysql_connect("localhost", "root", "1234") or die("Could not connect.");

if(!$db) 

	die("no db");

if(!mysql_select_db("forums",$db))

 	die("No database selected.");



?>
<?php 

include "conn.php"; //mysql db connection here

print "<link rel='stylesheet' href='style.css' type='text/css'>";

print "<A href='post.php'>New Topic</a><br>";

print "<table class='maintable'>";

print "<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>";

$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto asc";

$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 href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td>$getthreads3[showtime]<br>Last post by <b>$getthreads3[lastposter]</b></td></tr>";

}

print "</table>";



?>
<?php 

include "conn.php"; //mysql db connection here

$id=$_GET['id'];

print "<link rel='stylesheet' href='style.css' type='text/css'>";

print "<A href='index.php'>Back to main forum</a>-<A href='post.php'>New Topic</a>-<A href='reply.php?id=$id'>Reply<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 vakign='top'>Last replied to at $gettopic3[showtime]<br><hr>";

$message=strip_tags($gettopic3['post']);

$message=nl2br($message);

print "$message<hr><br>";

print "</td></tr>";

$getreplies="Select * from forumtutorial_posts where parentid='$id' order by postid asc"; //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 vakign='top'>Last replied to at $getreplies3[showtime]<br><hr>";

   $message=strip_tags($getreplies3['post']);

   $message=nl2br($message);

   print "$message<hr><br>";

   print "</td></tr>";

}

print "</table>";



?>
<?php

include "conn.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>";

?>
<?php

include "conn.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'];


   $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
      $name=strip_tags($name);

      $yourpost=strip_tags($yourpost); 

      $insertpost="INSERT INTO forumtutorial_posts(author,post,showtime,realtime,lastposter,parentid) values('$name','$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>";

?>
0

Thanks praveen_dusari.

hi mexabet,
you will have import option in your database and in conn.php

<?
mysql_connect("localhost","username","password");
mysql_select_db("databasename");
?>

and u need to include conn.php in every page where u use sql quieries

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.