Simple comment Box System using php | Sanwebcorner

Simple comment Box System using php

Hi ,I am going to explain about how to create simple comment box system using php. The comment system one of the important thing for blog or website because the user comments is publicly visible to all. Each and every customers know about others comments about the particular post or pages.

Most of the members using this comment box system for blog post. Another important thing is to validate the particular form fields to avoid unformulated data from the customer.

The below images shows how the comment box looks like.


Comment Box System: with Javascript validation


Index.php:

<?php include('head.php')?>
<?php
include('connect.php');
$select=mysql_query("select * from commentbox");
while($row=mysql_fetch_array($select))
{
echo "<div id='upstyle'>";
echo "<img src='man.png'"."' width='50px' height='50px' align='left' />";
echo "<div id='commname'>".$row['name']."</div>";
echo "<div id='commcomment'>".$row['comments']."</div>";
echo "</div><br />";
}
?>
<script type="text/javascript">
function validation()
{
var name=document.comment.name.value;//document.getElementById('name').value
if(name=="")
{
alert('Please Enter Your Name First');
//document.getElementById('san').innerHTML="please enter the name";
document.comment.name.focus();
return false;
}
var desig=document.comment.desig.value;
if(desig=="")
{
alert('Plese Enter Your Designation');
document.comment.desig.focus();
return false;
}
var email=document.comment.email.value;
if(email=="")
{
alert('Please Enter your Email ID');
document.comment.email.focus();
return false;
}
else
{
var ex=/^(([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4}))$/;
 if(ex.test(email)==false)
 {
  alert('Please Enter Valid Email ID');
document.comment.email.focus();
return false;
 }
}
/*<!--else
{
var pra=/^([0-9_\-\.\+\,])$/;
if(pra.test(email)==false)
{
alert('Enter Correct Contact Number');
document.comment.email.focus();
return false;
}
}-->*/
var comments=document.comment.comments.value;
if(comments=="")
{
alert('Please Enter Email ID');
document.comment.comments.focus();
return false;
}
}
</script>
<div align="center" style="width:2050px;">
</div>
<div class="center">
<h1 style="margin-left:50px; text-decoration:underline; text-align:center;">Comment Box </h1>
<form action="comment.php" method="post" onsubmit="return validation()"  name="comment" >
<strong class="lab">Enter Name:</strong> <input class="textbox" type="text"  name="name" style="margin-left:52px; "><br /><br />
<strong class="lab">Designation:</strong> <input class="textbox" type="text" name="desig" style="margin-left:52px;"><br /><br />
<strong class="lab">Email:</strong> <input class="textbox" type="text" name="email"  style="margin-left:100px;"><br /><br />
<strong class="lab">Comments:</strong><textarea cols="38" rows="5" name="comments"  style="margin-left:62px;"></textarea> <br /><br />
<input type="submit" class="submit" name="submit" id="submit" value="Submit">
</form>
</div>
<?php include('foot.php') ?>



head.php

<!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" />
<link rel="stylesheet" href="style.css" />
<title>Comment Box System</title>
<meta name="description" content="san insert data to database">
<meta name="author" content="getinn">
<meta charset="UTF-8">
</head>
<body>
<div class="head">
<BR />
<marquee style="color:#FFFFFF; letter-spacing:1PX;">create comment Box system using php and mysql with Javascript Validation</marquee>
</div>


foot.php

<div class="footer">
<br><br>
<p style="color:#FEFEFE; text-align:right; margin-right:80px;">Copyright &copy; 2014 | san web corner  &nbsp;<a href="http://www.sanwebtutorials.blogspot.in/">san web corner</a></p>
</div>
</body>
</html>



Comment.php

<?php
include("connect.php");
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$desig=$_POST['desig'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$insert=mysql_query("insert into commentbox(name,desig,email,comments)values('$name','$desig','$email','$comments')")or die(mysql_error());
header("Location:index.php");
}
?>


Connect.php:

<?php
$conn=mysql_connect('localhost', 'root', '');
$db=mysql_select_db('sancomment',$conn);
?>


Style.css

html, body {

  height: 100%;

  width: 100%;

  padding: 0;

  margin: 0;

  background-color:#FFFFFF;
}
.head
{
background-color:#a0c631;
height:60px;
}
.footer
{
background-color:#a0c631;
height:120px;
}
table
{
margin:0 auto;
font-family:Tahoma, Geneva, sans-serif;
margin-top:5px;
}
#text
{
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
height:40px;
border: 1px solid #898989;
}
#search {
font-size: 14px;
color:#FFFFFF;
padding: 12px 38px;
background: -moz-linear-gradient(
top,
#1d8cb1 0%,
#0f7ea3);
background: -webkit-gradient(
linear, left top, left bottom, 
from(#7c9b20),
to(#8eb420));
border: 1px solid #518206;
}

#search:hover
{
background:#5C9607;
}

.sansearch
{
width:500px;
size:10px;
margin-left:auto;
margin-right:auto;
}


.center
{
height:440px;
width:700px;
margin-left:auto;
margin-right:auto;
margin-top:50px;
margin-bottom:50px;
border:1px solid #B8B8B8;
border-radius:10px;
}

.container
{
width:1100px;
margin-left:auto;
margin-right:auto;
}


.san
{
width:800px;
margin-left:auto;
margin-right:auto;
border:1px solid #E3E3E3;
border-radius:10px;
height:auto;
line-height:20px;
padding-left:60px;
min-height:80px;
padding-top:10px;
padding-bottom:40px;
line-height:32px;
font-size:18px;
}

.textbox
{
height:30px;
width:300px;
border:1px solid #340001;
}
.lab
{
font-size:19px;
color:#050505;
font-weight:bold;
margin-left:50px;
}

.submit
{
height:30px;
width:100px;
border:1px solid #D3D3D3;
margin-left:350px;
margin-top:10px;
background-color:#6A9511;
color:#FFFFFF;
}
#upstyle
{
margin:0 auto;
margin-top:8px;
border-bottom-color:#333;
border:1px solid #CCC;
background:#EDEDED;
width:700px;
height:50px;
padding:15px;
}

img
{
margin-right:20px;
}
#commname
{
font-size:20px;
color:#000;
margin-bottom:8px;
}
#commcomment
{
font-size:18px;
color:#333;

margin-bottom:5px;
}



Post a Comment

Labels

360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient hide menu Horizontal News ticker Hover Htm Html html dropdown html form html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript Jquery js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form Multi-Step-form mysql News ticker on hover change text to image our team page password strength checker Photoshop PHP populate html selectbox Popup image on click the link pure css Question type form Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips Youtube