WebBalster3000
New Member
How would I add a comment box to my page? Looking for a something simple, just users name, comment, time and date, and maybe a rating system. I'm using Dreamweaver cs5. Thank You in advance.
<title>Untitled Document</title>
</head>
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST'){
$me = $_SERVER['PHP_SELF'];
?>
<body>
<p>Leave Comments:</p>
<form name="form1" method="post" action="<?php echo $me;?>">
<input name="user" type="text" size="25" maxlength="40" /><br /><br />
<textarea name="comments" cols="46" rows="7" wrap="PHYSICAL" id="comments"></textarea><br />
<input type="submit" name="Submit" value="Submit">
</form>
<?php
// calls information from database
$link = mysql_connect('host ip address', 'user name', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('database name') or die('Could not select database');
$sql = "SELECT * FROM tbl_comments";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
$i=0;
while ($i < $num) {
$user = mysql_result($result,$i,"user");
$date = mysql_result($result,$i,"date");
$comments = mysql_result($result,$i,"comments");
$i++;
}
mysql_close($link);
?>
<?php // displays the information called
echo $date ?> <?php echo $user ?><br /><br />
<?php echo $comments ?>
<?php // collects information and enters it into the database
} else {
error_reporting(0);
$user = $_POST['user'];
$comments = $_POST['comments'];
//$hour = date("h") + 1; //(added hour)
$hour = date("h") + 1;
$minute = date(":ia");
$month = date("l , F dS Y");
$date = $month . ' , ' . $hour . $minute;
$link = mysql_connect('host ip address', 'username', 'password')
or die('Could not connect: ' . mysql_error());
mysql_select_db('database name') or die('Could not select database');
$sql = "INSERT INTO tbl_comments
SET user = '$user', comments = '$comments', date = '$date'";
$result = mysql_query($sql)
or die('Could not update database: ' . mysql_error());
echo 'Thank you for your comments<br>';
mysql_free_result( $result );
// Closing connection
mysql_close($link);
echo 'You will now be redirected';
header("Refresh: 5; URL=http://www.yourpage.com");
}
?>
</body>