Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

How to save website comments to a database?

Me and a couple of mates were doing a website. It has a comment section for users and we would like to add a comment section. The question is, how do we get their comments submitted using the "Submit" button save to a database somewhere?

And the comments should also await admin approval before it can be displayed on the page.

Update:

Thanks for the tips. I do use Wampserver to manage the databases of PHp and MySQL but I'm no expert in getting them to connect.

3 Answers

Relevance
  • Teoma
    Lv 5
    9 years ago
    Favorite Answer

    You need to do this in something like PHP and a mySQL database, there's not much to learn to just run this setup.

    On submitting a comment it should have a column in the database schema that defines it as hidden, a simple 0 or 1 value, that an admin would be changing on reviewing the comment (also by submitting a form in most cases)

    You're PHP script would then run an SQL query like the following to list previous comments:

    SELECT `date`, `comment`, `username` FROM `comments` WHERE `hidden` = '0' LIMIT 10;

    Which only gets records that the admin has approved; because on first recording the comment `hidden` would be 1

    If you're having to learn this then maybe install this: http://www.wampserver.com/en/ It contains all the required components to run a web server with database on your own PC.

    The web is filled with tutorials on PHP and mySQL, you could easily have this done within a week if you bang your heads together ☺

  • 5 years ago

    You would need to know about doing mysql queries.. like INSERT (for inserting comment data) or UPDATE too (depending if you want comments to be edited for example) You should know about PHP's $_POST and how it works with a form so the form data (i.e the comment data) can be posted and processed. To not allow a form to be submitted unless it was were filled in you would need to do some php if statements .. e.g.. if($email && $comment == '') { echo 'Please fill in both fields } else { /// do mysql query here etc } You could do form validation with javascript to for better user experience... but highly recommended to validate on server side too incase javascript not enabled on users browser.

  • In simple terms, the SUBMIT button will call a php script something like submit.php and this script will send the comment to the database. One of the database fields should be APPROVED and the default should be 'no'.

    When you load the comments page, another php script will read the comments from the database and display them on the screen if APPROVED==Y

    That's the simplified version. You need to learn how to set up a simple mySQL table, how to call a php script from the SUBMIT button, how to submit a row into a mySQL table and how to read a mySQL table.

    If you know a bit of javascript, you should be able to figure out the php code for all this relatively easily with the help of some decent tutorials. You don't need to be an 'expert' although I admit it sounds intimidating at first.

Still have questions? Get your answers by asking now.