July 26, 200818 yr On my website www.triumphvillage.com, I have a section where I post my articles. I want readers to write their comments from the form, submit it and see it posted immediately after the article. I want the comments to contain their name, comments and time stamp. Just like a forum. I want these to be in my database as well. Can someone help me? Since I haven't been able to this 'add comment' action, I just allow my readers to submit their comments and send to my email. After that, I will post the comments manually. thanks
July 26, 200818 yr Yes - we can help you do that. Please feel free to pm or email me to discuss it further. Kind Regards Ed
July 26, 200818 yr Use PHP/MyAQL combo. The users' comments would be submitted (using a form) to a database, and show the database contents on the comments page.
July 28, 200818 yr Author Hi, thanks for your respond. Actually, I've tried to copy paste the html from a site. I'll show you how I did it below. This is the table comments: CREATE TABLE `comments` ( `commentid` int(11) NOT NULL auto_increment, `tutorialid` int(11) NOT NULL default '0', `name` text NOT NULL, `url` text NOT NULL, `comment` text NOT NULL, `email` text NOT NULL, `date` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`commentid`), KEY `tutorialid` (`tutorialid`) ) This is part of the 'inc_rate.php' file (it's too long to paste everything here): <? //Please set the following variables for your MySQL database: //Please set the following variables for your MySQL database: //it is highly recommended that you restrict access for the user for security reasons //it only needs "INSERT" privileges $db_hostname = "localhost"; //usually "localhost be default" $db_username = ""; //your user name $db_pass = ""; //the password for your user $db_name = ""; //the name of the database /*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS --------------------------------------*/ // connect to database $dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($db_name); This is the 'submitcomment.php': <?php //Please set the following variables for your mysql database: $db_hostname = "localhost"; //usually "localhost be default" $db_username = ""; //your user name $db_pass = ""; //the password for your user $db_name = ""; //the name of the database /*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS --------------------------------------*/ // connect to database $dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($db_name); $tuturl = $_POST["tuturl"]; $tutid2 = $_POST["tutid2"]; $name = $_POST["name"]; $url = $_POST["url"]; $email = $_POST["email"]; $message = $_POST["message"]; $sendcomment = mysql_query("INSERT INTO comments SET tutorialid='$tutid2', name='$name', url='$url', email='$email', comment='$message', date=now()"); if($sendcomment){ //header("Location: $tuturl"); echo "<h1>Submission Successful</h1>"; echo "Your comment has been submitted. You will now be redirected back to the last page you visited. Thanks!"; echo "<meta http-equiv='refresh' content='2;URL=$tuturl'>"; } else { echo "There was an error with the submission. "; } ?> So, I've made the table in mysql, made 2 php files, inc_rate.php and submitcomment.php. But, I have a question, I don't know where to put these: <?php require('inc_rate.php'); getComments("1"); submitComments("1","$PHP_SELF"); ?> The tutorial asked me to paste these in my html where I want the comments to be pasted. It doesn't work. For now, if anyone enters the comments and submit the form, I get the data posted onto my database, but it doesn't get pasted anywhere. Please help. Another thing, if I want the comments on separate pages under different articles where the articles are on individual pages, can I have a proper number increment? thanks
Create an account or sign in to comment