Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: creating a message board with php and mysql

  1. #1
    Overclocked si-skyline's Avatar
    Join Date
    Apr 2007
    Location
    sheffield, eng
    Posts
    438

    Default creating a message board with php and mysql

    hi guys, i was wondering if someone could help me out of this hard place im in, iv got to create a php and mysql based message board or bulleting board. but i dont really have a clue were to start.

    i was thinking of this at the moment...
    /mysql database
    //tbl_user
    userid*
    name
    dob
    email

    //tbl_theads
    theadid*
    userid
    dateposted
    header
    message

    * = primary key
    underline = forian key

    i think iv got the tables sorted. but my main consern is with the php side of things and how im going to present the data, is there any sugestions about how iv done it at the moment? is there any websites what will help me do this directly or indirectly by learning some php.

    just one note tho, this is my unis server and can only use the myphp webmin front of things. and cant install any server side things like phpbb.

    thank you very much and hope to hear from you soon. simon
    Basic Math:
    1 + 1 = 2
    1 * 1 = 1

  2. #2
    Spam Sniper SgtM's Avatar
    Join Date
    Jul 2005
    Location
    Ohio
    Posts
    4,545

    Default Re: creating a message board with php and mysql

    I was just about to suggest phpbb, it sucks that you can't install it. What about downloading it and sorting through the code?

  3. #3
    duct tape can fix anything Tavarin's Avatar
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    186

    Default Re: creating a message board with php and mysql

    All righty then. I've been learning how to code PHP for a few months now, and I already have a message board-esque style script under my belt.

    Here's a site you can visit to learn some PHP:
    http://w3schools.com/
    It can teach you how to connect to a database, add and remove items from a table, call items, etc...

    What you're going to want to do is create a form that will allow you to post data into your table. Then you're going to want to make a page that uses PHP script to access and display this data. If you'd like I can send you some of my own scripts that might help you out. They're really simple, I'd just need a little bit to customize them to your needs.

    Cheers

  4. #4
    Overclocked si-skyline's Avatar
    Join Date
    Apr 2007
    Location
    sheffield, eng
    Posts
    438

    Default Re: creating a message board with php and mysql

    i think if i did it that sgtm i think i would start being confussed by the code they are using, iv never seen it before by i can guess its going to be quite complacated

    tavarin, that would be cool, the most iv learned about php at the moment is to connect to a database make a query and to diplay the data in a table while not fully understanding how the data is sorted.

    thank you very much guys
    Basic Math:
    1 + 1 = 2
    1 * 1 = 1

  5. #5
    duct tape can fix anything Tavarin's Avatar
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    186

    Default Re: creating a message board with php and mysql

    Well here's a very quick message board script I wrote:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Message Boards</title>
    </head>

    <body>

    <?php
    //connect to a database

    mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("database name") or die ('I cannot connect to the database because: ' . mysql_error());

    //Get current date and set as a variable

    $dateadd=date("j of F Y, \a\\t g.i a", time());

    //If someone wants to delete a message then this is what the command getrs sent to

    if($mode=="remove") {
    mysql_query("DELETE FROM messageboards WHERE number = $ID");
    }

    //Saves what the user has inputed to a form into the database along with the date

    if($mode=="add") {
    mysql_query("INSERT INTO messageboards (name, date, title, message)
    VALUES ('$_POST[nameadd]', '$dateadd', '$_POST[titleadd]', '<pre>$_POST[messageadd]</pre>')")
    or die ('I cannot add message because: ' . mysql_error()); }

    //Get all the table information and arrange newest to oldest

    $result = mysql_query("SELECT * FROM messageboards ORDER BY number DESC");

    //Make each column an array

    while($row = mysql_fetch_array($result)) {
    $number[]= $row['number'];
    $n_name[]= $row['name'];
    $date[]= $row['date'];
    $title[]= $row['title'];
    $message[]= $row['message']; }

    //start making a table

    echo "<table border='1' width='500px'>";

    //display each message from the database in this table

    for ($i = 0; $i < sizeof($number); $i++) {
    echo "<tr><td>" . $n_name[$i] . "</td></tr>";
    echo "<tr><td>" . $date[$i] . "</td></tr>";
    echo "<tr><td><strong>" . $title[$i] . "</strong></td></tr>";
    echo "<tr><td>" . $message[$i] . "</td></tr>";
    echo "<tr><td><a href=\"$PHP_SELF?ID=$number[$i]&mode=remove\">Delete Message</a></td>";
    echo "<tr><td><br /><br /></td></tr>"; }
    echo "</table>";

    //The form from which someone can post a message

    echo "
    <form method='POST' action=\"$PHP_SELF?ID=$number[$i]&mode=add\">
    <p><strong>Name: </strong><br /><input type='text' size='50' name='nameadd' /><br />
    <strong>Message Title: </strong><br /><input type='text' size='50' name='titleadd' /><br />
    <strong>Message: </strong><br /><textarea cols='70' rows='20' name='messageadd' wrap='virtual'></textarea><br />
    <input type='submit' value='Add Message' /></p><br />
    </form>";

    ?>

    </body>

    </html>
    Any italicized text needs to be changed

    It may seem a little crazy, and I'll explain it if you'd like, but if you'd like to use this script you'll need a table like this:

    $sql = "CREATE TABLE messageboards
    (
    number int NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(number),
    name varchar(50),
    date varchar(50),
    title varchar(50),
    message varchar(10000)
    )";
    Now the actual message boards page I made is an all in one page without password protection. It allows anyone to submit their name, a title and a message to the database. It then finds and adds the date to the same row. Then it will display each message in order from most recent to oldest.

    Go here and you can see the example I made. It looks ugly but it works:

    http://www.actonhighschool.ca/7/Message.php

    Good luck, and if anyone would like to suggest anything then please do so.

  6. #6
    Overclocked si-skyline's Avatar
    Join Date
    Apr 2007
    Location
    sheffield, eng
    Posts
    438

    Default Re: creating a message board with php and mysql

    your example is perfect, its jsut what im looking for, im sorry that im not too up to speed with php but can i ask what does

    if($mode=="add")

    mean? is that like bind to a button on the page? i dont understand the "mode" thing.. i can see that its ment to be adding a message to the board.

    thank you so much for taking your time to give me the example

    ps.. there is no italic coding on the post xD

    pps. dont want to dp.. i have given the code a wack and everything works fine untill i came to use the functions of adding and deleting a message... i filled the form in and pressed add.. wam it apeared to work but no message. so i hit f5 to refresh thinking that will do it but there is nothing in the database as well..

    so i though it might be wrong on my side so i put some values in the database and tryed agian and it showed the data.. i also gave delete a go and that didnt work either :/

    do i need to set permissions on the database? can i do it thu php webmin?
    Basic Math:
    1 + 1 = 2
    1 * 1 = 1

  7. #7
    duct tape can fix anything Tavarin's Avatar
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    186

    Default Re: creating a message board with php and mysql

    you're welcome, and now I shall do my best to answer your questions.

    $mode is a variable I made that allows everything to be done on a single page.
    The add form begins like this:
    <form method='POST' action=\"$PHP_SELF?ID=$number[$i]&mode=add\">
    This action reloads the page with the values placed in the form field posted, and with $mode set to add.
    The line if($mode=="add") is just checking to see if the variable mode has been set to add, and if it has been (as done by the forms action and submit), executes it's code.

    There is also a $mode=="remove" which is set when the remove link below any message is pressed.

    The only text I italicized was in the connection portion of the code. the username, password, and database name all had to be changed to whatever your values are.

    And I think you're right about why you can't add or remove messages, you may not have the permissions. PHP webmin should let you change the permissions rather easily, but I've never used it, so I'm not 100% sure.

    Anyway, hope that helps clear some things up. If you have any more question, or any more problems, just post them up.

    Cheers

  8. #8
    Overclocked si-skyline's Avatar
    Join Date
    Apr 2007
    Location
    sheffield, eng
    Posts
    438

    Default Re: creating a message board with php and mysql

    thanks for the HUGE help, +rep

    i still cant get to finding permissions or what im screwing up on.. i think il try on my own server.. see if its the uni being a double s holes or now xD

    i did manage to find something similer to your consept but they didnt say anything about permissions either
    Basic Math:
    1 + 1 = 2
    1 * 1 = 1

  9. #9
    duct tape can fix anything Tavarin's Avatar
    Join Date
    Feb 2008
    Location
    Canada
    Posts
    186

    Default Re: creating a message board with php and mysql

    well the permissions is the only thing I can think of that might be causing the errors, since I've run this exact code on my own server and it works just fine. I do hope you can figure out what is going wrong, and get this working.

    And if you'd like to password protect the form at the bottom of the page I have a really simple password protect script that just runs for one page load. It'll be only seconds to put in, the only problem being that the way I did it you can only have one username. I'm still working on creating a multi-user password lock using cookies and a database. If I'm successful I'll send the script your way.

    Cheers

  10. #10
    Overclocked si-skyline's Avatar
    Join Date
    Apr 2007
    Location
    sheffield, eng
    Posts
    438

    Default Re: creating a message board with php and mysql

    yeah that would be quite useful.. is it because you cant get the link between the UN with the PW?
    Basic Math:
    1 + 1 = 2
    1 * 1 = 1

Posting Permissions

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