Php code for Comment on Webpage

Php code for Comment on Webpage
$Yourwebpage.php
<!-- Comment Entry Section  !-->
    <table cellpadding="0" cellspacing="0"><tr>
      <td width="25%" valign="top"><form method="post" action="<? echo $pfile;?>" name="comment">
          <table bgcolor="silver" align="center" cellpadding="5" cellspacing="0" width="270px">
            <tr>
              <th colspan="2"><? if($_POST["do_comment"]==1) {
                                        $name=$_POST["name"];
                                        $email=$_POST["email"];
                                        $website=$_POST["website"];
                                        $comment=$_POST["comment"];
                                        $page=$_POST["page"];
                                        $status=0;
                                        $page=$_post["page"];
                                        $query="insert into comment values('$name','$email','$website','$comment',$status,'$pfile')";
                                        $result=mysql_query($query);
                                        if($result!=NULL)
                                            echo "<font color='red'>Thanks for your comment ; Your comment need approval after approval it will be display on website.</font><br>";
                                    }
                                    ?>
                <? $file = $_SERVER["SCRIPT_NAME"];
                                    $break = Explode('/', $file);
                                    $pfile = $break[count($break) - 1];
                                    ?>
                Write your comment</th>
            </tr>
            <tr>
              <td>Enter Your Name</td>
              <td><input type="text" size="20" name="name" /></td>
            </tr>
            <tr>
              <td>Enter Your Email</td>
              <td><input type="text" size="20" name="email" /></td>
            </tr>
            <tr>
              <td>Enter Your Blog</td>
              <td><input type="text" size="20" name="website"  value="http://"/></td>
            <tr>
              <td colspan="2">Enter Your Comment</td>
            </tr>
            <tr>
              <td colspan="2" align="center"><textarea rows="5" cols="25" wrap="virtual" name="comment"></textarea></td>
            </tr>
            </tr>
            <tr>
              <td colspan="2" align="center"><input type="hidden" name="do_comment" value="1" />
                <input type="hidden" name="page" value="<? echo $pfile; ?>" />
                <input type="submit" value="Submit" />
                <input type="reset" value="Clear" /></td>
            </tr>
          </table>
        </form>
  
  </td>
      <td valign="top"><!-- Comments Display Section  !-->
          <div id="comment">
            <center>
              <b>Comment on <? echo $pfile; ?></b>
            </center>
            <br />
            <?
                        $query="select * from comment where page='$pfile' and status='1'";
                        $result=mysql_query($query);
                        $temp=0;
                        while ($row = mysql_fetch_array($result)) {
                            $temp=1;
                            if($row[2]==NULL || $row[2]=="http://")
                                echo "<b>",$row[0]," (",$row[1],") </b><i>Wrotes</i> <b>",$row[3]," </b><hr>";
                            else
                                echo "<a target='_blank' href='",$row[2],"'><b>",$row[0],"</a> (",$row[1],")</b><i> Wrotes </i><b>",$row[3],"</b><hr>";
                        }
                        if($temp==0)
                            echo "<i>No comment on this section</i>";

                        ?>
          </div>
   <div align="right" style="padding:5px;" ><a href="comment.php" style="color:#0000FF">View All</a></div>
</div>
</center>

    </td>
      </tr></table>
OUTPUT
 
Fig-1
Table of Enquiry
CREATE TABLE `comment` (
  `name` varchar(20) NOT NULL default '',
  `email` varchar(40) default NULL,
  `blog` varchar(40) default NULL,
  `comment` text,
  `status` tinyint(1) default '0',
  `page` varchar(20) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Comment will be Display on web page when status will be 1. So create admin section to change or alter the Data of comment posted by the user or you can store 1 when you don't need of authorization required.
 
"Php code for Comment on Webpage" Php code is made for Distribution purpose;
Modify it as per your requirement.

if you want to share your story or article for our Blog please email us at educratsweb@gmail.com or Click here

Post a Comment

0 Comments