Welcome to WebDesignForums.net!
You're currently viewing WDF as a guest. By registering for a free account, you'll be able to participate with other members in our friendly community. Being a member allows you to ask questions and get answers for those troublesome web development tasks!

In addition, as a member you'll be able to post your websites up for review. Using our unique website review system you can gain some amazing feedback from some of the best web developers around. This is a completely free service to all registered members.

Ready to register yet? Registration is 100% free. Click Here To Join Now!

Php comment system help

Discussion in 'PHP' started by cyroxos, Apr 24, 2006.

  1. Offline

    cyroxos New Member

    Message Count:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Good day, I am creating a personal profile website and have run into a problem with a php comment system that I got to work. I can get the comment script to work on one page; however, if I include my php script on another page, it will display the same comments.


    I suppose the page URL needs to be uploaded to the database along with the other three fields, COMMENT, NAME, and WEBSITE. As of how, I do not know. Also, the script needs to filter out any database entries that do not match the page URL.

    I am probably explaining this pretty bad, here is the source of my php script
    name: Phpcomment.php
    Code:
    <?PHP
    
    $root_path = '/home/ftpusername/public_html/';
    
    $url = 'http://www.cyroxos.net/Phpcomment/';
    
    $host         = 'localhost'; //server host
    $database     = 'data'; //database name
    $user         = 'xxxxxx'; //database username
    $pass         = 'xxxxxx'; //database password
    
    $limit         = '10'; 
    
    ?>
    
    <?PHP
    $con=mysql_connect("$host","$user","$pass"); $db="$database"; mysql_select_db($db, $con);
    $svr_domain     = "http://$_SERVER[HTTP_HOST]";
    $svr_phpself     = "$_SERVER[PHP_SELF]";
    $svr_self     = "$svr_domain$svr_phpself";
    
    if (empty($_GET[limit])) $limit = $limit; else $limit = $_GET[limit];
    
    if ($_GET[shout] == 1 && $_POST[COMMENT] != $nil && $_POST[NAME] != $nil) {
        $controller     = $_POST['controller'];
        $pieces     = explode("~", $controller);
        $table         = $pieces[0];
        $qt         = $pieces[1];
        $return     = $pieces[2];
        $id         = $pieces[3];
        $hack         = $pieces[4];
    
        if ($qt == insert) 
            $qt = 'INSERT INTO';
        if ($qt == update) { 
            $qt = 'UPDATE'; $end = "WHERE ID = '$id'"; 
        }
    
        $pre         = array_keys( $_POST );
    
        mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
    
        $count         = count($pre); 
        $count         = $count - 2;
        $sql         = "$qt $table SET";
        
        for ($i=0; $i < $count; $i++) {
            $x    = $i+1;
            $y     = $_POST[$pre[$x]];
            $d     = $y;
    
            if ($pre[$x] == REQUIRED || $pre[$x] == NODUPE || $pre[$x] == NOPASS) {
            } else {
                mysql_query ("ALTER TABLE `$table` ADD `$pre[$x]` TEXT NOT NULL");
                $sql .= " `$pre[$x]` = '$d',";
            }
        }
    
        $sql .= " ID = '$id' $end";
        $query = mysql_query($sql) or die("$sql_error" . mysql_error());
    }
    ?>
    <FORM METHOD="post" ACTION="?shout=1">
     <INPUT TYPE="hidden" NAME="controller" VALUE="COMMENTS~insert~<?PHP ECHO "$svr_self"; ?>~<?php echo $id; ?>">
     <TABLE BORDER=0 ALIGN=center CELLPADDING=4 CELLSPACING=0 WIDTH=100%>
      <TR> 
       <TD CLASS="tdhead" WIDTH="100%" >Last 
        <?php echo $limit; ?>
        Comments [ <A HREF="?">Reload</A> ]</TD>
      </TR>
      <?PHP
    $SQL = "SELECT * from COMMENTS ORDER BY ID DESC LIMIT $limit"; $result = @mysql_query( $SQL ); while( $row = @mysql_fetch_array( $result ) ) {
    ?>
      <TR> 
       <TD CLASS="tdmenu" WIDTH="100%" > 
        <?php echo "<b>$row[NAME]</b> : $row[COMMENT]"; if ($row[WEBSITE] != $nil) { echo " [ <a href=\"$row[WEBSITE]\" target=blank>$row[NAME]'s Website</a> ]"; }?>
       </TD>
      </TR>
      <?PHP } ?>
      <TR> 
       <TD CLASS="tdmenu" WIDTH="100%" >[ <A HREF="?limit=1000">Show Last 1000</A> ]</TD>
      </TR>
     </TABLE>
     <BR>
     <TABLE BORDER=0 ALIGN=center CELLPADDING=4 CELLSPACING=0 WIDTH=100%>
      <TR>
                <TD CLASS="tdhead" colspan="2" NOWRAP>Post Comment</TD>
            </TR>
      <TR>
                <TD CLASS="tdmenu" WIDTH="1%" NOWRAP>Name</TD>
                <TD CLASS="tdmenu" WIDTH="100%" >  
        <INPUT TYPE="text" NAME="NAME" SIZE="35"></TD>
            </TR>
      <TR>
                <TD CLASS="tdmenu" WIDTH="1%" NOWRAP>Website</TD>
                <TD CLASS="tdmenu" WIDTH="100%" >  
        <INPUT TYPE="text" NAME="WEBSITE" SIZE="35" VALUE="http://www."></TD>
            </TR>
      <TR>
                <TD CLASS="tdmenu" WIDTH="1%" NOWRAP>Comment</TD>
                <TD CLASS="tdmenu" WIDTH="100%" ><textarea name="COMMENT" rows="4" cols="40"></textarea>
        </TD>
            </TR>
            <tr>
                <td class="tdmenu" width="1%" nowrap></td>
                <td class="tdmenu" width="100%"><INPUT TYPE="submit" NAME="Submit" VALUE="Add Comment"></td>
            </tr>
        </TABLE>
     </FORM>
    
    and it is included into the page via <?PHP INCLUDE "Phpcomment.php"; ?>

    The page: http://www.cyroxos.net/weblog.php

    I am sorry for this extensive request, but I must say, it has me very confused. Thank you.


  2. Offline

    bfsog Coder

    Message Count:
    2,354
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    UK
    I do not understand what you seek,

    Do you want to display the blog but without the comments?


  3. Offline

    ablaye New Member

    Message Count:
    45
    Likes Received:
    0
    Trophy Points:
    0
    I don't understand what you mean either. Please give more details.


  4. Offline

    cyroxos New Member

    Message Count:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Once again, I am sorry for being unclear.
    I want to be able to use this comment system on multiple pages--Such that each page has unique comments to that page. At the moment, wherever I put the script, the comments get uploaded to the same place in my mysql database.
    So what I need is a way to add a field that detects the page URL and uploads it along with the other comment fields. Then, when the scrip displays the data on the page, I need a way for it to filter out only the uploaded comments that have a matching page URL.

    Is this any more clear? I am sorry.


  5. Offline

    bfsog Coder

    Message Count:
    2,354
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    UK
    Ah I see, like if the page is "value1.php" only display comments where it's page (or other column name) is equal to "value1.php"

    The way I do this is, I have two tables, one for the posts/articles that you make, and one for the comments.

    When a new comment is added I insert the post/article id into a int column in the comments table.

    Then, to extract the comments for a particular post/article, your query would be like:
    PHP:

    $select_q 
    "SELECT * FROM comments WHERE aid = $aid";
    Where $aid is the post/article id number.


Share This Page