Hey guys this is the following script for the comment box. You can use this code in your website if you want to. You can also use it as your reference in learning advance PHP.

This is the Print Screen of the comment Script..

Try it!!
This script is for those who already have a background in PHP or other programming language..

1st Step .The first Step is to create a database.

Requirements: XAMPP,Web  Browser.

You need to create database name “comment_notification”, table “comment_box” with a field names “num” as integer, “user “as varchar, “email” as varchar, and “message” as longtext.

Okay! Lets now go to the main event, the programming..

This code is for the connectiuon to database.

Read the instruction carefully.

<?php

mysql_connect(“localhost”,”root”) or die(“error connecting to database”);

mysql_select_db(“comment_notification”) or die(“error selecting database”);

$counter=mysql_query(“select * from comment_box”);

$result=mysql_num_rows($counter);

?>

This code is for the starting tag of the html and for the css which holds your PHP script.

<html>

<head>

<title>Untitled Document</title>

Start of the CSS.

<style>

body{

background-color:#333333; text-align:center;}

#holder{

margin-bottom:auto;

margin-left:auto;

margin-right:auto;

background-color:#666666;

height:auto;

margin-bottom:10px;

width:300px;

padding:5px;

-moz-border-radius:20px;

border-radius:20px;

color:#FFFFFF;

}

#comments{

background-color:#CCCCCC;

color:#333333;

-moz-border-radius:20px;

border-radius:20px;

padding:10px;

text-align:left;

}

#design{  color:#333333;

}

</style>

End of the CSS

</head>

And now this is the code for the comment to be posted.

<body>

<?php

$user=$_POST[‘user’];

$email=$_POST[’email’];

$message=$_POST[‘message’];

$scan=strpos($email,’@’);

if($scan==true)

{

if(!isset($_POST[‘save’]) || ($user==””) || ($message==””) || ($email==””))

{$note=”all fields are required”;

}

else

{

mysql_query(“insert into comment_box(user,email,message) values(‘$user’,’$email’,’$message’)”);

}

}

else

{

$note=”You entered invalid <b>email address</b>”;

}

$query=mysql_query(“select * from comment_box”);

$numrows=mysql_num_rows($query);

//this the id for the comments result

?>

<div>

<div>

<?php

if($numrows>0)

{echo ‘<table border=0>’;

while($numrows>0)

{  $getdata=mysql_fetch_array($query);

echo ‘<tr><td><b>NAME :</b></td><td>’.$getdata[‘user’].'</td></tr>’;

echo ‘<tr><td><b>E-mail :</b></td><td>’.$getdata[’email’].'</td></tr></table>’;

echo ‘<center>Comment :<br></center>’.$getdata[‘message’];

echo ‘<br><center><div id=”design”>——————–</div></center>’;

$numrows–;

}

echo'</table>’;

}

else

{

echo “No Comments found <br>”;

}

?>

</div>

</div>

<!–form class –>

<center>.

And now the form, this is where you will write your comments

<div>

<form action=”try.php” method=”post”>

<?php echo ‘<center>’.$note.'</center>’;?>

<table>

<tr>

<td>Name</td> <td><input name=”user” maxlength=”20″  /></td></tr>

<tr><td>E-mail</td><td><input name=”email” maxlength=”50″  /></td></tr>

</table>

Write your Comment Here ! <br />

<textarea cols=”30″ rows=”5″>

</textarea>

<br />

<input value=”comment” />

</form>

</div>

</center>

</body>

</html>

Share on Google+Tweet about this on TwitterShare on FacebookShare on TumblrShare on StumbleUponPin on PinterestShare on LinkedInDigg thisShare on RedditEmail this to someone