Comment BOX
May 14, 2008
//Create Table
CREATE TABLE `comments` (
`id` int(11) auto_increment,
`name` varchar(30) NOT NULL,
`email` varchar(30) NOT NULL,
`comment` varchar(200) NOT NULL,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
//comment.php
<?php
if(isset($_POST['posted'])){
$coment = add_to_database();
if(!$coment){
print “Eror: Databases Error”;
}
}
//show get data to browser
mysql_connect(“localhost”,”root”) or die(“Could not Connect”);
mysql_select_db(“cse_rental”) or die(“Could not Select Datadase”);
$result = mysql_query(“SELECT * FROM comments”);
$count = mysql_num_rows($result);
print “There R Currently $count Comments”;
while($q = mysql_fetch_array($result)){
?>
<style type=”text/css”>
* {
font-family:Verdana, Sans-serif;
color; #000000;
font-size: 12px
}
input,textarea{
color : #000000;
font: normal 12px;
border-collapse: collapse; border: 1px solid #000000;
}
</style>
<table width=”50%”>
<tr>
<td rowspan=’3′ valign=’top’ width=”1%”>
<?php echo $q[id]; ?>.
</td>
<td bgcolor=”#009966″>Comments:</td>
</tr>
<tr><td bgcolor=”#FFFFCC”>
<?php echo $q[comment]; ?>
</td></tr>
<tr><td bgcolor=”#CCCCCC”>This Comment is posted by <b><?php echo $q[name]; ?></b> on <?php echo $q[date]; ?></td></tr>
</table>
<?php
}
mysql_close();
?>
<!– Input from user –>
<form action=”comment.php” method=”post” enctype=”multipart/form-data”>
<input type=”hidden” name=”posted”>
<b>Add Your Comments</b><br />
Name:<br />
<input type=”text” name=”name” maxlength=”30″ size=”32″><br />
Email:<br />
<input type=”text” name=”email” maxlength=”30″ size=”32″><br />
Comments:<br />
<textarea cols=”40″ rows=”6″ name=”comment”></textarea><br />
<input type=”submit” value=”Add Comments”><input type=”reset” value=”Reset”>
</form>
<?php
//add to database
function add_to_database()
{
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$comment = trim($_POST['comment']);
mysql_connect(“localhost”,”root”) or die(“Could not Connect”);
mysql_select_db(“cse_rental”) or die(“Could not Select Datadase”);
$sql = “INSERT INTO comments (`id`,`name`,`email`,`comment`)
VALUES(”,’$name’,'$email’,'$comment’)”;
mysql_query($sql);
mysql_close();
return true;
}
?>









Trackback this post | Subscribe to the comments via RSS Feed