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;
}

?>

Entry Filed under: MySQL, PHP. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


My Fav




My twiTTer

Error: Please make sure the Twitter account is public.

Top Clicks

 

May 2008
M T W T F S S
    Jul »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Category Cloud

JAVA Java Script MySQL Networking(CISCO) PHP Template Uncategorized

Recent Comments

pollobcse05 on About
মাহমুদ ফয়সাল on About
pollobcse05 on Connecting MySql With Jav…
Shamim Ahmed on Connecting MySql With Jav…
Arafat Rahman on My First WordPress Templa…

Blogroll

Meta

My Flickr Photos

SDC12881

SDC12818

SDC12808

SDC12802

SDC12794

More Photos

Pages

Blogroll

Meta