Using PHP and IIS to Create a Discussion Forum

db , mysql , php United Kingdom
This is a comment thread discussing Using PHP and IIS to Create a Discussion Forum
  • 17 years ago

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

  • 17 years ago
    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  
  • 17 years ago
    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
  • 17 years ago
    Can PHP interact with SQL Server? If yes, how can it do?
  • 17 years ago

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

  • 17 years ago

    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.

  • 17 years ago

    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

  • 17 years ago

    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?

  • 17 years ago

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

  • 17 years ago
    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


  • 17 years ago

    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]')");

  • 17 years ago

    I'm gest curios.

  • 17 years ago

    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?

  • 17 years ago
    have you got register_globals turned on in the PHP.ini
  • 17 years ago

    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

  • 17 years ago
    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.

  • 17 years ago

    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)



  • 17 years ago

    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

  • 17 years ago


    It works fine for me in MS-SQL

  • 17 years ago
    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
  • 16 years ago
    i'm getting this error messagewen i go to node.php Notice: Undefined variable: node in C:\IS_Intranet\node.php on line 15
  • 16 years ago

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

  • 16 years ago

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

  • 16 years ago

    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

  • 16 years ago

    hello,


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


    Thanks
    Laxy
    www.funspot.com

  • 16 years ago

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



    any ideas?

  • 16 years ago

    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?

  • 16 years ago
    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!
  • 16 years ago
    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.
  • 16 years ago

    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.


    [email protected]


    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 years ago

    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.


    [email protected]


    Cheers
    Brian

  • 16 years ago


    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;
  • 15 years ago

    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.


  • 15 years ago

    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.

  • 15 years ago

    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.

  • 14 years ago
    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.

  • 13 years ago

    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!

  • 11 years ago
    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 :

  • 11 years ago
    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]
  • 11 years ago
    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 :

  • 11 years ago
    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 :

  • 11 years ago
    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 "
  • "; 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
  • 11 years ago

    I have searched a lot to find where i can

    create free email and web forms.Finally after lot of

    searching i find a site where i can create email forms,web

    forms, php forms, contact forms for free and in easy way. its link is http://www.ezcontactform.com/

  • 10 years ago

    cool guys! co-occur the latest untrammelled casino games like roulette and slots !after outlet the all chic deliver online casino games at the all up to the minute www.casinolasvegass.com, the most trusted online casinos on the net! use our free casino software download and advance in money. you can also discontinuation other online casinos bonus .

  • Post a reply

    Enter your message below

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

    Quick links

    Recent activity

    Contribute

    Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

    Our tools

    We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

    “A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson