Hi all,
Am dropping this coz some are having problem with it, all procedures on how to do it is in the code, read well and edit well! :)
Hope it helps!
Am dropping this coz some are having problem with it, all procedures on how to do it is in the code, read well and edit well! :)
<?php
//connect to your database, fillup the database details
$dbhost = "";// Your database hostname
$dbuser = "";// your database username
$dbname = "";//Your database name
$dbpwd = "";//Your database password, leave empty if your database don't have password
$connect = mysql_connect($dbhost,$dbuser,$dbpwd);
if(!$connect)
{
die('Could not connect to database due to the following reasons: '.mysql_error());
}
mysql_select_db($dbname);
?><!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" />
<title>Untitled Document</title>
</head>
<body>
<?php
//checking if comment has been made
if(isset($_POST['comment']))
{
$comment = mysql_real_escape_string(trim($_POST['comment']));
if(!$comment)
{
die('Enter Comment');
}
/*inserting comment into database, with the following columns in the table
*id = which the comment id which will auto increase when ever comment is made
*topic_id = Every comment must have a topic it is commenting for, so that the topic id from another table you created, you can hold it with a session or hidden form
*reply = this is the main body of the reply message
*uid = It must be a user that should made the comment and so from your users table you get the id column and hold it with a session, cookie or hidden form
*date = Surely, it must have a date*/
//now inserting into database, using example of topic id = 1 and
$date = date('d/m/Y');
mysql_query("insert into comment(topic_id,reply,uid,date)values('1','$comment','1','$date')") or die('Could not insert comment into database due to the following reasons: '.mysql_error());
}
//show comment for a particular topic, assumming the topic id is 1 and user id is also 1
$query = mysql_query("select * from comment where topic_id='1'");
if(!$query)
{
die(mysql_error());
}
while($row = mysql_fetch_array($query))
{
$topic_id = $row['topic_id'];
$uid = $row['uid'];
$reply = $row['reply'];
$date = $row['date'];
?><a href="">user<?=$uid?></a>: <?=$reply?><br/><?=$date?><br/>
<?php }
?>
<form action="" method="post">
<textarea placeholder="Reply" name="comment"></textarea>
<input type="submit" value="Comment" />
</form>
Created by <a href="http://2netlodge.com">2netlodge</a>
</body>
</html>
Hope it helps!
No comments:
Post a Comment