Hello all! I hope I am posting under the correct Forum. I am new to PHP code, but I am affluent in regular HTML code. I run an obscure movie review website and here's my problem. I would like to be able to have a comment section below each movie review where someone can leave their comment and it gets posted directly under the review on the same page. I’ve been reading up on PHP for around 4 hours today and can’t seem to find any useful information. Luckily I stumbled upon this forum.

So could anyone assist me in doing this? I will definitely give you complete credit for coding on the website for the help.

Here are some movie review websites with a comments section for examples:

http://bloody-disgusting.com/review/822
http://www.twitchfilm.net/archives/002261.html

Or even this comment form which is on a PHP tutorial site, but I still don't have a clue how to go about creating it:

http://www.tipsntutorials.com/tutorials/PHP/50

Thanks,

~ Chris Mayo

    First you will have to look at HTML forms. Here is an example:

    <form name="comment_form" method="post" action="example.php">
    <label for="poster_name">Name:</label>
    <input type="text" name="poster_name" size="20" maxlength="32" /><br />
    <label for="poster_email">Email:</label>
    <input type="text" name="poster_email" size="20" maxlength="32" /><br />
    <label for="poster_comment">Comment:</label>
    <textarea name="poster_comment" rows="10" style="width:300px"></textarea><br />
    <input type="submit" value="Post comment!" name="submit_btn" id="submit_btn" />
    </form>
    

    To process the values entered by the user, you must have a script doing that. In this case the script is example.php.
    There are two ways of transmitting information submitted: GET and POST.
    Transmitting with GET will result, that values entered in fields will show up in your browsers address bar. POST is "silent".
    In PHP there are a few ways to get submitted values: there are some predefined variables, which get these values.
    For example if we use the POST method, then the values will show up in the $POST predefined variable(array).
    These said, the name of poster will be found in $
    POST['poster_name'], and so on...

    So here is example.php written for you:

    <?php
    if (isset($_POST['submit_btn'])) { // submit button was pressed, so a comment was submitted
      // Do anything you want with comment
      // for example print out
      print('Comment posted by: '.$_POST['poster_name']);
      print('With e-mail address: '.$_POST['poster_email']);
      print('His/her comment: '.$_POST['poster_comment']);
    }
    print('
    <html>
    <body>
    <form name="comment_form" method="post" action="example.php">
    <label for="poster_name">Name:</label>
    <input type="text" name="poster_name" size="20" maxlength="32" /><br />
    <label for="poster_email">Email:</label>
    <input type="text" name="poster_email" size="20" maxlength="32" /><br />
    <label for="poster_comment">Comment:</label>
    <textarea name="poster_comment" rows="10" style="width:300px"></textarea><br />
    <input type="submit" value="Post comment!" name="submit_btn" id="submit_btn" />
    </form>
    </body>
    </html>
    ');
    ?>
    

    The isset function is returning true, if the variable passed as argument exists(is set). So if the submit button was pressed, the $_POST['submit_btn'] variable will be set, and more, will have the value "Post comment!".
    If isset returns true, you may want to store the comment in your database and display it, or whatever you want.

    Hope it helps, good luck.

      Thanks for the help SZZ. I did basically what you said, but I still don't understand how the outcome of the form gets saved onto the same page. Here is an example of what I just uploaded to my server:

      Example Review Page

      What am I missing?

      Thanks again.

      ~ Chris

        Your page is called example.html posting to example.php

        It needs to be example.php posting to example.php

          Hmm, I just tried renaming the main file to example.php, and it worked less. Oh well. I have no clue what I'm doing. It seems no tutorial online gives you the full information either.

          Thanks anyway guys...

          ~ Chris

            there would be plenty of tutorials around, you just might need to addapt them a little. try doing a google for a php guestbook or shoutbox, then go from there.

              Originally posted by Chris Mayo
              Hmm, I just tried renaming the main file to example.php, and it worked less. Oh well. I have no clue what I'm doing. It seems no tutorial online gives you the full information either.

              Thanks anyway guys...

              ~ Chris

              One more question: where are the comments stored?
              I mean in a database, or some textfile, ...?

                Generally, I don't recommend posting to the same page. Eventually you'll have a page that gets too bogged down with code.

                I prefer to have an intermediate page that does the "work" of posting data to your database (or text file, etc.). That intermediate page then redirects the user back to the page they came from. It's similar to the way it's done here at phpbuilder.

                Just my $.02...

                  Buzzly,

                  Your color picker is pretty damn nifty.

                  bookmarked

                    Originally posted by Kudose
                    Buzzly,

                    Your color picker is pretty damn nifty.

                    bookmarked

                    Better download it, before he starts charging!

                    J

                      I didnt realize I could...

                      searches franticly

                        Sweet...Got the source.

                        Thanks for pointing out I could download the source.

                        Thanks to Buzzly for the generous contribution.

                          Originally posted by Kudose
                          Buzzly,

                          Your color picker is pretty damn nifty.

                          bookmarked

                          Thanks! From now on, I'm going to charge $1.99 per use, and $99 for downloa -- oh, dammit. Too late 🙂

                          I may put a PayPal link on there in case anyone wants to donate to the cause, but I'll never charge for it 🙂

                            Originally posted by szz
                            One more question: where are the comments stored?
                            I mean in a database, or some textfile, ...?

                            I have no idea where it saves. Nowhere I presume, since I don't know what I'm doing. I go have something called MySQL or something installed on my server but I have no clue how to utilize it for a database. I've attempted several tutorials, but they don't contain enough basic knowledge for me to follow and comprehend them...

                            ~ Chris

                              You need to buy 2 books then.

                              1 about MySQL and 1 about PHP.

                              I recommend SAMS Teach yourself MySQL in 24 hours, and CORE PHP Programming, revised for PHP5

                                are you looking to store the comments, or just email the results to you?

                                  Originally posted by Kudose
                                  Buzzly,

                                  Your color picker is pretty damn nifty.

                                  bookmarked

                                  Whø ïn thè wørld wøùld ùsè sømèthïng Bùzzly màdè? Í mèàn, SÈRÍØÜSLY, whø ïn thèïr rïght mïnd... øh, wàït.

                                  EDIT: Just read the creds. Did Buzzy make it or dale? shrugs

                                    Originally posted by bradgrafelman
                                    Whø ïn thè wørld wøùld ùsè sømèthïng Bùzzly màdè? Í mèàn, SÈRÍØÜSLY, whø ïn thèïr rïght mïnd... øh, wàït.

                                    EDIT: Just read the creds. Did Buzzy make it or dale? shrugs

                                    The word you want to search on is "bork". Long story.

                                      Dalecosp provided the initial code for replacing vowels with accented equivalents, with his blessing to do as I wanted with it. I expanded on it a bit, and wrapped it up in the Børkínätør® app.

                                      I have no problem giving credit where credit is due 🙂

                                        Write a Reply...