Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Is there a video that shows how to make comments on your site?

I know it has something to do with using a php form and then saving the user input somewhere in a directory and then echoing it on the screen, but is there a specific video for this?

4 Answers

I would prefer to watch one of the videos explaining how to do this instead of copying a code from google that I'm sure is full of errors...

So I made a html comments page with a form, and and action page that is echoing the variable onto the screen, but what I'm missing is how to save the variable's value and then display what is saved onto the comments page. I believe there is some kind of query required for this??

<!DOCTYPE html>

<html> <head> <meta charset="utf-8"> <title>Comments</title> <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel="stylesheet" type="text/css"> <link href="https://fonts.googleapis.com/css?family=Spirax" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Italianno" rel="stylesheet"> <link href="style.css" rel="stylesheet"> <script src= "scripts.js"> </script> </head>

<body>

<form action="commentaction.php" method="post">

  <legend class="formtitle"><h49>Please Leave Your Comments</h49></legend>
  <fieldset>

  <label for="name"><h49>Your name?</h49></label>
  <input type="text" id="name" name="name">



  <label for="details"><h49>Your Comment?</h49></label>
  <textarea id="details" name="details"></textarea>

  <button type="submit">Submit</button>
  </fieldset>

 </form>
</body>

</html>

HERE IS THE PHP action page:

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

$name = trim(filter_input(INPUT_POST,"name",FILTER_SANITIZE_STRING));
$email = trim(filter_input(INPUT_POST,"email",FILTER_SANITIZE_EMAIL));
$details = trim(filter_input(INPUT_POST,"details",FILTER_SANITIZE_SPECIAL_CHARS));

 echo $name;

echo $details; exit; }

?>

Tianni Myers
Tianni Myers
10,453 Points

Are you serious? You can search google for videos as well...

Then what am I paying for treehouse for Tianni? I can search google for anything. I'm looking for a treehouse video that explains how to do this. You could answer anybodys questions on here why don't you go search google, but that's not helpful to me.

Tianni Myers
Tianni Myers
10,453 Points

If you think Treehouse will supply you with all the information you need to know about programming then you’ve mistaken. Something so specific like “how can I add comments to my site in PHP” is perfect for a search on google to find a video such as this: https://www.youtube.com/watch?v=kWOuUkLtQZw

Well I think they should provide you with all the information you need especially something as common as making comments, but I guess they also assume that if you learn to code php you wouldn't have a problem figuring out how to link your form to your database. I'm still learning php its a pain....

The video you gave actually is very good, thanks Tianni!