Library tutorials & articles

Using PHP and IIS to Create a Discussion Forum

Conclusion

Hopefully this article has shown you that PHP is very versatile, and works well with a variety of different platforms, web servers and databases I think this article has been the perfect example of how, in just 10 minutes or so, we can use PHP to create a basic discussion forum that makes use of a powerful database.

If you're just coming to grips with PHP, then why not take this discussion forum and turn it into something spectacular? There are an infinite number of ways that you could expand it. Feel free to post in our forums to discuss your ideas.

Comments

  1. 31 Mar 2009 at 10:37
    This is forum.php file and the earlier code is node.php Discussion Forum using PHP/Access under IIS

    Post New Message "; while(odbc_fetch_row($noderesult)) // get all the rows { $code = odbc_result($noderesult,"code"); $title = odbc_result($noderesult,"title"); $uname = odbc_result($noderesult,"uname"); $email = odbc_result($noderesult,"email"); echo "
  2. "; echo " $title "; echo "-- by ($uname) $email - Delete
    "; shownode($code); } echo ""; } function delnode($code) { global $connect; // using the global variable for connection // Get a list of all the sub nodes which specific parentcode $noderesult = odbc_exec($connect,"delete * from forum where code = $code"); echo ""; } ?> # Someone please tell me how to delete my earlier post
  • 31 Mar 2009 at 10:34
    Post to Discussion Forum using PHP/Access under IIS
    "; $noderesult = odbc_exec($connect,"select * from forum where code = $node"); $noderow=odbc_fetch_row($noderesult); $title = odbc_result($noderesult,"title"); $description = odbc_result($noderesult,"description"); $uname = odbc_result($noderesult,"uname"); $email = odbc_result($noderesult,"email"); echo "$title by ($uname) $email
    "; echo "$description

    "; } ?>
    Name :
    E-Mail :
    Title :
    Description :

  • 31 Mar 2009 at 10:34
    Post to Discussion Forum using PHP/Access under IIS
    "; $noderesult = odbc_exec($connect,"select * from forum where code = $node"); $noderow=odbc_fetch_row($noderesult); $title = odbc_result($noderesult,"title"); $description = odbc_result($noderesult,"description"); $uname = odbc_result($noderesult,"uname"); $email = odbc_result($noderesult,"email"); echo "$title by ($uname) $email
    "; echo "$description

    "; } ?>
    Name :
    E-Mail :
    Title :
    Description :

  • 31 Mar 2009 at 10:32
    node.php [code]
    Post to Discussion Forum using PHP/Access under IIS
    "; $noderesult = odbc_exec($connect,"select * from forum where code = $node"); $noderow=odbc_fetch_row($noderesult); $title = odbc_result($noderesult,"title"); $description = odbc_result($noderesult,"description"); $uname = odbc_result($noderesult,"uname"); $email = odbc_result($noderesult,"email"); echo "$title by ($uname) $email
    "; echo "$description

    "; } ?>
    Name :
    E-Mail :
    Title :
    Description :

    [/code]
  • 31 Mar 2009 at 10:29
    Although this is old thread, but the issues is look's great. I have tested the code and it seem that need some modification- for file (forum.php) Discussion Forum using PHP/Access under IIS

    Post New Message "; while(odbc_fetch_row($noderesult)) // get all the rows { $code = odbc_result($noderesult,"code"); $title = odbc_result($noderesult,"title"); $uname = odbc_result($noderesult,"uname"); $email = odbc_result($noderesult,"email"); echo "
  • "; echo " $title "; echo "-- by ($uname) $email - Delete
    "; shownode($code); } echo ""; } function delnode($code) { global $connect; // using the global variable for connection // Get a list of all the sub nodes which specific parentcode $noderesult = odbc_exec($connect,"delete * from forum where code = $code"); echo ""; } ?>
    And for file (node.php)
    Post to Discussion Forum using PHP/Access under IIS
    "; $noderesult = odbc_exec($connect,"select * from forum where code = $node"); $noderow=odbc_fetch_row($noderesult); $title = odbc_result($noderesult,"title"); $description = odbc_result($noderesult,"description"); $uname = odbc_result($noderesult,"uname"); $email = odbc_result($noderesult,"email"); echo "$title by ($uname) $email
    "; echo "$description

    "; } ?>
    Name :
    E-Mail :
    Title :
    Description :

  • 20 Aug 2007 at 11:16

    Hi

    I've gone through the instructions to install PHP and test, create the access database, add the two PHP files and then test the forum.

     

    I can access forum.php fine and input data into node.php but when I click on 'Post Message' my inputted text disappears and nothing is written to the Access database?  I thought it may have been a permissions issue but both 'Everyone' and the 'IUSR' account have Full Control NTFS permissions to the Access database?

    I've tried using both version 4 and version 5 of PHP but get the same problem?

    Can you advise?

    Thanks!

  • 08 Mar 2007 at 17:23
    People might want to note that you must have PHP version 4 for this to work, it will not work for version 5.  I think if php.exe is replaced with php-win.exe it might work in version 5.

  • 23 Aug 2005 at 20:43

    I check the node.php file and the the above line of code are exactly the same.  I still get the same error "Notice: Undefined variable: node in c:\Inetpub\wwwroot\node.php on line 15".  The error is in the line if ( $node != 0 ).  I jus want to see how a simple forum works.  Thanks for your help.

  • 30 Jun 2005 at 12:44

    If we install the php binary then the PHP will run as binary. But I want to run it as a module. Please help me with necessary infomation.

  • 21 Jun 2005 at 01:23

    I added php4isapi.dll for executeable it's working fine but one problem if i try to access my .php file by typing the the actual url (like www.abtcom.com.au/index.php ) it is asking me for user name and password. But it is not asking me for the .html file. does any one know what is the reason?


    i could not find any clue for that.


  • 03 Feb 2005 at 15:04


    I've amended the code to 1) work 2) work with MySql (see table at bottom)


    forum.php:

    Code:

    <? # original code Jayesh Jain, amends by me, still needs form input validation, etc
    include("connect.php"); # Your connection details?>
    <HTML>
    <BODY>
    Discussion Forum using PHP/<s>Access</s> MySql under <s>IIS</s> Apache<BR>
    <BR>
    <A HREF='node.php?node=0'>Post New Message</A>
    <?


    shownode(0); // display all the main threads


    // This function is a recursive function which shall display all the branches
    // and sub branches of the threads
    function shownode($nodecode) {
      global $link; // using the global variable for connection
      // Get a list of all the sub nodes which specific parentcode
      #$noderesult = odbcexec($connect,"select * from forum where parentcode = $nodecode");
     
      $sql = "SELECT code, title, uname, email FROM forum WHERE parentcode = '$nodecode'";
      $result = mysql
    query($sql);
     
      echo "<UL type='disc'>";
      while(list($code, $title, $uname, $email) = mysqlfetchrow($result)) {
          echo "<LI>";
          echo "<A HREF='node.php?node=$code'> $title </A>";
          echo "-- by ($uname) $email<BR>";
          shownode($code);
      }
      echo "</UL>";
    }?>
    </BODY>
    </HTML>


    node.php:
    Code:

    <? # original code Jayesh Jain, amends by me, still needs form input validation, etc
    include("connect.php"); # Your connection details


    $submit = $POST[submit];
    if(isset($submit)) // check if submitted button is clicked
    {
      // insert the record in the database
      $sql = "INSERT INTO forum (parentcode,title,description,uname,email) VALUES ('$
    POST[node]','$POST[title]','$POST[description]','$POST[postname]','$POST[email]')";
      #echo "<br>".$sql."<br>";
      $result = mysqlquery($sql);
     
      header("location:forum.php"); // open forum.php file to display the thread
    }
    ?>
    <CENTER>Post to Discussion Forum using PHP/<s>Access</s> MySql under <s>IIS</s> Apache</CENTER>
    <?
    $node = $
    GET[node];
    if ( $node != 0 ){
      // Displaying the details of the thread
      echo "<HR>";
     
      $sql = "SELECT code, title, uname, email FROM forum WHERE code = '$node'";
      #echo "<br>".$sql."<br>";
      $result = mysqlquery($sql);
      list($code,$title,$uname,$email) = mysql
    fetchrow($result);?>
      <?=$title?> by (<?=$uname?&gt <?$email?><BR>
      <?=$description?>
      <BR>
      <HR>
    <?}?>
    <!-- Form to enter the message -->
    <FORM method='post' action='node.php'>
    Name : <INPUT TYPE=TEXT NAME=postname> <BR>
    E-Mail : <INPUT TYPE=TEXT NAME=email> <BR>
    Title : <INPUT TYPE=TEXT NAME=title VALUE = '' size=50> <BR>
    Description : <BR> <TEXTAREA name=description rows=10 cols=45></TEXTAREA>
    <!-- we need a hidden field to store the node -->
    <INPUT TYPE=hidden NAME=node value='<? echo $
    GET[node];?>'> <BR>
    <INPUT type=submit name=submit value='Post Message'>
    </FORM>


    and finally MySql table (as original, really):


    #
    # Table structure for table `forum`
    #

    CREATE TABLE forum (
     code int(11) NOT NULL auto_increment,
     parentcode int(11) NOT NULL default '0',
     title text NOT NULL,
     description text NOT NULL,
     uname text NOT NULL,
     email text NOT NULL,
     UNIQUE KEY code (code)
    ) TYPE=MyISAM;
  • 18 Nov 2004 at 03:02

    Hi, did you ever get this problem fixed as I have the same one! Please email the reply to me as well as to the group.


    ashnook@o2.co.uk


    Cheers
    Brian

  • 18 Nov 2004 at 03:01

    Hi, did you ever get this problem fixed as I have the same one! Please email the reply to me as well as to the group.


    ashnook@o2.co.uk


    Cheers
    Brian



    Quote:
    [1]Posted by roccotaco on 12 Nov 2004 06:17 AM[/1]
    i've tried your forum tutotial but i get this error read when i try and access the page:


    Warning: odbc_connect() [function.odbc-connect]: SQL error: , SQL state 00000 in SQLConnect in c:\Inetpub\wwwroot\worstmetteamever\forum\index.php on line 3
    Discussion Forum using PHP/Access under IIS


    Post New Message
    Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in c:\Inetpub\wwwroot\worstmetteamever\forum\index.php on line 20



    Warning: odbcfetchrow(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\worstmetteamever\forum\index.php on line 22


    i had previously installed php w/ iis and i think i need to wipe php off my system and start over again.  what files did i need to erase  besides going to add/remove programs?


    thanks for any help!

  • 16 Nov 2004 at 00:45
    Hi,

       This is Ravi from India.  I am new to PHP. My issue is " I am unable to insert information into Access, which has been passed from another php file form.  I used many options like "$empno" , ' ".$empno." '  ,    '$empno'  and    $empno  in Insert statement  where empno is a textfield name.  Please specify how to gather 'string'and number variables.

       I tried the example of node.php and forum.php   but i have the same problem.    Any help is greatly appreciated.


    Thank you.
  • 12 Nov 2004 at 06:17
    i've tried your forum tutotial but i get this error read when i try and access the page:

    Warning: odbc_connect() [function.odbc-connect]: SQL error: , SQL state 00000 in SQLConnect in c:\Inetpub\wwwroot\worstmetteamever\forum\index.php on line 3
    Discussion Forum using PHP/Access under IIS

    Post New Message
    Warning: odbc_exec(): supplied argument is not a valid ODBC-Link resource in c:\Inetpub\wwwroot\worstmetteamever\forum\index.php on line 20


    Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\worstmetteamever\forum\index.php on line 22

    i had previously installed php w/ iis and i think i need to wipe php off my system and start over again.  what files did i need to erase  besides going to add/remove programs?

    thanks for any help!
  • 25 Oct 2004 at 11:10

    ok removing the ! fixed the error message but I was having another problem as well as this that is still there......I cannot make any posts BIG PROBLEM lol



    any ideas?

  • 25 Oct 2004 at 11:05

    I had the same problem I have removed the ! and the error has gone but I still cannot create any new posts



    any ideas?

  • 18 Sep 2004 at 00:39

    hello,


    Friends please help me Can I compile php with mysql without having mysql sources?


    Thanks
    Laxy
    www.funspot.com

  • 04 Sep 2004 at 14:08

    this is the error i got from my forum page


    Discussion Forum using PHP/Access under IIS


    Post New Message
    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot find the input table or query 'forum'. Make sure it exists and that its name is spelled correctly., SQL state S0002 in SQLExecDirect in c:\Inetpub\wwwroot\Forum.php on line 20



    Warning: odbcfetchrow(): supplied argument is not a valid ODBC result resource in c:\Inetpub\wwwroot\Forum.php on line 22



    this is the error i got from the node page


    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Could not find output table 'forum'., SQL state S0002 in SQLExecDirect in c:\Inetpub\wwwroot\node.php on line 8


    Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\wwwroot\node.php:8) in c:\Inetpub\wwwroot\node.php on line 9




    can someone help me

  • 06 May 2004 at 17:12

    Remove the exclamation mark (!) so it looks like ($node= 0)

  • 06 May 2004 at 17:11

    To Solve this Simply Remove the Exclamation mark So it looks like this ($node=0)

  • 15 Apr 2004 at 09:09
    i'm getting this error messagewen i go to node.php Notice: Undefined variable: node in C:\IS_Intranet\node.php on line 15
  • 03 Mar 2004 at 05:01
    i got the following error when i was trying to run the "forum.php"

    Warning: odbc_connect(): SQL error: [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data., SQL state S1000 in SQLConnect in c:\inetpub\wwwroot\forum.php on line 3
    Discussion Forum using PHP/Access under IIS


    advice needed urgently!!!

    thanks
  • 28 Jan 2004 at 15:12


    It works fine for me in MS-SQL

  • 28 Jan 2004 at 15:10

    Get documentation at
    http://www.mysql.com/doc/en/CREATE_TABLE.html


    install ODBC for MySQL
    then create a ODBC connection to mysql with name "forum"


    then create a table with


    CREATE TABLE  forum
    (
    code  INTEGER AUTO_INCREMENT,
    parentcode INTEGER NOT NULL DEFAULT 0,
    title  VARCHAR(50) NOT NULL DEFAULT '',
    uname  VARCHAR(50) NOT NULL DEFAULT '',
    email  VARCHAR(50) NOT NULL DEFAULT '',
    description TEXT DEFAULT ''
    )


    then you should use the right user name / password while connnecting
    thats it

  • 28 Jan 2004 at 14:45

    I am running IIS on WinXP Pro and account used for anonymous access is IUSR_APPLE


    1.
    One issue I found was IUSR_APPLE not having write access to Forum.mdb
    So I changed to have read, write, modify access



    2.
    Next issue was form variables are not automatically converted to php var.
    I think this is a setting issue.
    But I used a temp solution.
    Added following statement in beginning of node.php



    if(isset($node)) $node=0;
    if(isset($GET[node])) $node=$GET[node];
    if(isset($POST[node])) $node=$POST[node];



    and changed sql insert statement to


      $sql = "insert into forum  (parentcode,title,description,uname,email) "
           . " VALUES   ($node,'$POST[title]', '$POST[description]',"
           . "'$POST[postname]','$POST[email]')";


      $resultupdate=odbc_exec($connect, $sql );




    3.
    Last issue, if email field is blank it created problem
    so I changed setting in Access to allow zero length value
    for all text fields and defaulted to ''
    (I did not mind blank fields)



  • 14 Aug 2003 at 08:22
    hi
    i faced the same problem then i found out that the .exe file in the php folder has an error when i execute the file so all what you have to do is just bring another .exe file that execute the php code and replace and make sure that the file is not corapted.

  • 28 Jul 2003 at 20:38

    Hello
    I am getting the following message, I have obviliously done something wrong...please help!


    "CGI Error
    The Specified CGI application misbehaved by not returning a complete set of HTTP headers.  The header it did return are:"


    I am running win2K sp3 and IIS 5


    TIA

  • 23 Jul 2003 at 23:55
    have you got register_globals turned on in the PHP.ini
  • 08 Jul 2003 at 09:45

    I have the same problem as nay27uk where when clicking on the links in the forum page, it goes through to the node page, it forms the connection, skips over the next piece and hits the 'if ($node != 0)' this is where the problem is. Does anyone know why? It does not seem to be able to find the $node variable for some reason. Unfortunately I don't fully understand how php works yet.


    Can some one help me?

  • 03 Jul 2003 at 06:26

    I'm gest curios.

  • 29 May 2003 at 07:16

    The latest releases of PHP have changed the way we access form variables. The problem line should be changed to


    $resultupdate=odbcexec($connect,"insert into forum
      (parentcode,title,description,uname,email) VALUES
      ($
    POST[node],'$POST[title]','$POST[description]','$POST[postname]','$POST[email]')");

  • 24 Apr 2003 at 20:34
    ERRRRM.

    I followed the instructions closely but keep geting this eror  whats making it hapen


    Notice: Undefined variable: node in c:\inetpub\wwwroot\node.php on line 15


  • 11 Apr 2003 at 01:26

    please do a php - mysql example to. pardon for my english! i will be glad if you help me make a database in mysql and also how to connect it in php. thank you in advance..

  • 26 Mar 2003 at 22:28

    Is PHP powerful like ASP in database functions (focus on MSSQL Server), ex: calling stored procedure,....
    I think that PHP database functions are designed towards MySQL. Is that wrong?

  • 26 Mar 2003 at 22:08

    Hi
    this must be because the register_globals = off in your php.ini


    please set it to register_globals=on


    else


    in the node.php
    add the following on the top of the file


    $title = $POST['title'];
    $description = $
    POST['description'];
    $uname = $POST['uname'];
    $email = $
    POST['email'];
    $node = $_POST['node'];


    Regards
    Jayesh Jain

  • 25 Mar 2003 at 15:42

    Hi I am useing php/mysql on iis ........... for some reason I can view my database fileds from php, but I can not insert into my database using my php form,  after the database connection I build my insert command, and in results only the auto_increment field is being added....... help pls.

  • 25 Mar 2003 at 05:13

    yes, using its standard odbc database functions - the same way PHP has accessed an Access database here.

  • 19 Mar 2003 at 04:01
    Can PHP interact with SQL Server? If yes, how can it do?
  • 12 Mar 2003 at 23:19
    Hi Jayesh,

    Thanks for your swift response; I have playing around with ASP for about 12 month but only been leaning php for about 2 weeks so still a NewB. This is great just what I've been in search of.

    Many Thx
    LeeB
  • 12 Mar 2003 at 22:45
    Hi

    Your Wish is my command

    Code:

    -------------forum.php-----------
    <?
    // This is the DSN we have create for our database
    $connect = mysql_connect("localhost","","") or die ("Unable To Connect To Database");
    ?>
    <HTML>
    <BODY>
    Discussion Forum using PHP/Access under IIS<BR><BR>
    <A HREF='node.php?node=0'>Post New Message</A>
    <?

    shownode(0); // display all the main threads

    // This function is a recursive function which shall display all the branches
    // and sub branches of the threads
    function shownode($nodecode)
    {
    global $connect; // using the global variable for connection
    // Get a list of all the sub nodes which specific parentcode
    $noderesult = mysql_query("select * from forum where parentcode = $nodecode");
    echo "<UL type='disc'>";
    while($noderow=mysql_fetch_array($noderesult) // get all the rows
    {
    $code = $noderow['code'];
    $title = $noderow[title];
    $uname = $noderow[uname];
    $email = $noderow[email];
    echo "<LI>";
    echo "<A HREF='node.php?node=$code'> $title </A>";
    echo "-- by ($uname) $email<BR>";
    shownode($code);
    }
    echo "</UL>";
    }
    ?>
    </BODY>
    </HTML>


    ------------node.php----------

    <?
    $connect = mysql_connect("localhost","","") or die ("Unable To Connect To Database");
    if(isset($submit)) // check if submitted button is clicked
    {
    // insert the record in the database
    $resultupdate=mysql_query($connect,"insert into forum
    (parentcode,title,description,uname,email) VALUES
    ($node,'$title','$description','$postname','$email')");
    header("location:forum.php"); // open forum.php file to display the thread
    exit;
    }
    ?>
    <CENTER>Post to Discussion Forum using PHP/Access under IIS</CENTER>
    <?
    if ( $node != 0 )
    {
    // Displaying the details of the thread
    echo "<HR>";
    $noderesult = mysql_query("select * from forum where code = $node");

    $noderow=mysql_fetch_array($noderesult);
    $title = $noderow[title] ;
    $description = $noderow[description] ;
    $uname = $noderow[uname];
    $email = $noderow[email];

    echo "$title by ($uname) $email<BR>";
    echo "$description <BR><HR>";
    }
    ?>
    <!-- Form to enter the message -->
    <FORM method='post'">
    Name : <INPUT TYPE=TEXT NAME=postname> <BR>
    E-Mail : <INPUT TYPE=TEXT NAME=email> <BR>
    Title : <INPUT TYPE=TEXT NAME=title VALUE = '' size=50> <BR>
    Description : <BR> <TEXTAREA name=description rows=10 cols=45></TEXTAREA>
    <!-- we need a hidden field to store the node -->
    <INPUT TYPE=hidden NAME=node value='<? echo $node;?>'> <BR>
    <INPUT type=submit name=submit value='Post Message'>
    </FORM>

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

    Hope this helps

    Cheers

    Jayesh Jain  
  • 12 Mar 2003 at 12:15

    Super, smashing, great, but haven’t got IIS.
    Please! How do I get this to work with Linux and MySQL?

  • 01 Jan 1999 at 00:00

    This thread is for discussions of Using PHP and IIS to Create a Discussion Forum.

  • Leave a comment

    Sign in or Join us (it's free).

    Jayesh Jain Jayesh Jain is working as a Business Analyst in Auckland, New Zealand. He has several years of n-Tier development experience in developing interactive client solutions. He has a passion for Web dev...

    Related articles

    Related discussion

    Related podcasts

    Events coming up

    Web Development

    We'd love to hear what you think! Submit ideas or give us feedback