SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Mark L's Avatar
    Join Date
    Aug 2003
    0 Post(s)
    0 Thread(s)

    Simple Forum Help

    I want to create an extreamly simple forum. I can make a simple guestbook where users can add info to a database by filling in a form but i need to go one step further and alow a "new post" to create a new page and maybe a new table (to keep it simple). The code i use for the guestbook is as follows...

    PHP Code:

    mysql_connect($host,$username,$password)or die(mysql_error());
    mysql_select_db($database)or die(mysql_error()); ?>

    <form action="<?=$PHP_SELF?>?page=guestbook&action=post" method="post" name="guestbook" id="guestbook">
     <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Your Name:
       <input name="name" type="text" id="name">
       Your E-mail:
       <input name="email" type="text" id="email">
       Your Message:<br>
       <textarea name="message" cols="50" rows="4" id="message"></textarea>
     <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
       <input name="Add" type="submit" id="Add" value="Add to guestbook">
       </font> </p>
    </form>         <br><p><a href=#bottom><b>Click here to go to the most recent message</b></a></p><br>

    if($action=="post") {

       if(!isset($message) OR $message=="" OR !isset($name) OR $name=="") {
         $dontadd = 1;
         print "You didn't enter your name and/or your message. Please try again.<br><br>";

       if(!isset($email) OR $email=="") {
         $email = "Unknown";

       if($dontadd!=1) {

       if($postedalready!=1) {
       $newid = mysql_insert_id();
       $datenow = date ("jS F Y", mktime ("NOW()") );
       mysql_query("INSERT INTO guestbook VALUES ('$name','$message','$datenow','$email')");

       $thanks = "<font size=2 face=Verdana, Arial, Helvetica, sans-serif>Thank you for your message!</font><br>";

       $postedalready = 1;


    $sql = mysql_query("SELECT * FROM guestbook");
    while ($gb = mysql_fetch_array($sql)) {
       $name = $gb["name"];
       $message = $gb["message"];
       $posted = $gb["posted"];
       print "<b>Posted by $name on $posted</b>.<br>$message<br><br>";

    <a name="bottom">
    Could somone please help me by replying, or contacting me via:

    AIM: no7leaside


  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2001
    Michigan, USA
    0 Post(s)
    0 Thread(s)
    The simplistic way to handle this would be to pretend that the coding you currently have will be used for a reply since posts are all added to the same page.

    That leaves you with the task of coming up with a way for posting a new topic. My recommendation would be to use the same form. When you are adding a new reply, send the topic id in a hidden form field for processing. If you are adding a new topic, do not send a topic id.

    Depending on whether or not you have an id, you can choose how to process your results. Add another field in your database for the topic id, and store it. Use the next available id if none was provided.

    Then, when you want to print a specific topic, simply add "topicid = $topic_to_view" to the WHERE part of your mySQL query.

    Obviously, there are better methods for writing a simple message software, but this will be one of the simplest ones given the code you have.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts