I would like to know what is the HTML/PHP code to allow a person to post a comment on a website?
I am going to design a website with this ability the customers can post comments?
You want a guestbook, and it is quite easy to achieve.http://www.phpeasystep.com/phptu/15.html
There’s also http://www.dreambook.com if you don’t want to get into the nitty-gritty of it.
You can also search out shoutboxes, which are quite popular on the Web.
You’re going to find that this is not as easy as you might think.
You can use a CMS (Content Management System) that has the code already developed for you, just integrate into your website.
Or you can write your own from scratch. This will require a database to store the comments. Be sure to validate your user input too!
Both ways have their pros and cons, its up to you to decide which route to go. Do a Google search for tutorials or scripts, if you want.
Here is a little comment system I put together.
This is not a “shout out” type system. I will add support for that in another version.
This system is meant for you to collect comments from users about your site. You can enable email too.
If you would like this BETA version just email support@dzsoundnirvana.com
or download it below.
Instillation notes are are the bottom of this page.
WARNING – LONG ANSWER
DIY method
—————–
You will need a MySQL database as well. Get a MySQL database and use the following code:
CREATE TABLE `comments` (
`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL ,
`subject` VARCHAR( 255 ) NOT NULL ,
`body` VARCHAR( 10240 ) NOT NULL
) ENGINE = MYISAM ;
Then you need to use this PHP code to write a comment (assuming you’re using the POST method – change accordingly):
< ?php
// Connect to MySQL
mysql_connect("my_server", "my_username", "my_password")
or die(mysql_error());
mysql_select_db("my_database")
or die(mysql_error());
// Write comments query
$query = "INSERT INTO comments ("name", "subject", "body") VALUES ("{$_POST['name']}", "{$_POST['subject']}", "{$_POST['message']}")";
// Escape it - be secure!
$new_query = mysql_real_escape_string($query);
// Write
mysql_query($new_query);
// Close connection
mysql_close();
echo("Comment added!");
?>
And here’s the code for reading comments and putting it in a table:
< ?php
// Connect to MySQL
mysql_connect("my_server", "my_username", "my_password")
or die(mysql_error());
mysql_select_db("my_database")
or die(mysql_error());
// Read comments
$result = mysql_query("SELECT * FROM comments")
or die(mysql_error());
// Put in array
$array = mysql_fetch_assoc($result)
or die(mysql_error());
// Output
echo '
‘;
echo ‘
‘;
echo ‘
Name
‘;
echo ‘
Subject
‘;
echo ‘
Message
‘;
echo ‘
‘;
while($array){
echo ‘
‘;
echo ‘
‘ . $array['name'] . ‘
‘;
echo ‘
‘ . $array['subject'] . ‘
‘;
echo ‘
‘ . $array['body'] . ‘
‘;
echo ‘
‘;
}
echo ‘‘;
// Close connection
mysql_close();
?>
Now, I’m unsure if this code will work or not, as I haven’t had the time to check it, but it should give a general idea of how this works.
Like others have suggested, you could also use pre-made solutions, but it’s unclear if those solutions will be suitable enough. This is just some PHP code I threw together in a few minutes for this answer.
You want a guestbook, and it is quite easy to achieve.http://www.phpeasystep.com/phptu/15.html
There’s also http://www.dreambook.com if you don’t want to get into the nitty-gritty of it.
You can also search out shoutboxes, which are quite popular on the Web.
You’re going to find that this is not as easy as you might think.
You can use a CMS (Content Management System) that has the code already developed for you, just integrate into your website.
Or you can write your own from scratch. This will require a database to store the comments. Be sure to validate your user input too!
Both ways have their pros and cons, its up to you to decide which route to go. Do a Google search for tutorials or scripts, if you want.
Here is a little comment system I put together.
This is not a “shout out” type system. I will add support for that in another version.
This system is meant for you to collect comments from users about your site. You can enable email too.
If you would like this BETA version just email support@dzsoundnirvana.com
or download it below.
Instillation notes are are the bottom of this page.
WARNING – LONG ANSWER
DIY method
—————–
You will need a MySQL database as well. Get a MySQL database and use the following code:
CREATE TABLE `comments` (
`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL ,
`subject` VARCHAR( 255 ) NOT NULL ,
`body` VARCHAR( 10240 ) NOT NULL
) ENGINE = MYISAM ;
Then you need to use this PHP code to write a comment (assuming you’re using the POST method – change accordingly):
< ?php
// Connect to MySQL
mysql_connect("my_server", "my_username", "my_password")
or die(mysql_error());
mysql_select_db("my_database")
or die(mysql_error());
// Write comments query
$query = "INSERT INTO comments ("name", "subject", "body") VALUES ("{$_POST['name']}", "{$_POST['subject']}", "{$_POST['message']}")";
// Escape it - be secure!
$new_query = mysql_real_escape_string($query);
// Write
mysql_query($new_query);
// Close connection
mysql_close();
echo("Comment added!");
?>
And here’s the code for reading comments and putting it in a table:
< ?php
// Connect to MySQL
mysql_connect("my_server", "my_username", "my_password")
or die(mysql_error());
mysql_select_db("my_database")
or die(mysql_error());
// Read comments
$result = mysql_query("SELECT * FROM comments")
or die(mysql_error());
// Put in array
$array = mysql_fetch_assoc($result)
or die(mysql_error());
// Output
echo '
echo ‘
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
while($array){
echo ‘
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
}
echo ‘‘;
// Close connection
mysql_close();
?>
Now, I’m unsure if this code will work or not, as I haven’t had the time to check it, but it should give a general idea of how this works.
Like others have suggested, you could also use pre-made solutions, but it’s unclear if those solutions will be suitable enough. This is just some PHP code I threw together in a few minutes for this answer.
Categories
Tags
Entries (RSS) and Comments (RSS). | developed by Point47