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 trialMartina Carrington
15,754 PointsUsing A Third-Party Library
I was following the steps on the video but when i preview it i got a couple of error message on suggest.php .
<?php if($_SERVER["REQUEST_METHOD"] == "POST"){ $name = trim(filter_input(INPUT_POST,"name",Filter_SANITIZE_STRING)); $email = trim(filter_input(INPUT_POST,"name",Filter_SANITIZE_EMAIL)); $details = trim(filter_input(INPUT_POST,"name",Filter_SANITIZE_CHARS));
if ($name == ""|| $email == "" || $details == ""){ echo "Please fill in the required field: Name, Email and Details"; exit; } require("inc/phpmailer/class.phpmailer.php");
echo "<pre>"; $email_body = ""; $email_body .= "Name " . $name . "\n"; $email_body .= "Email " . $email . "\n"; $email_body .= "Details " . $details . "\n"; echo $email_body; echo "</pre>";
//To Do: Send Email header("location:suggest.php?status=thanks"); }
$pageTitle = "Suggest a Media Item"; $section = "suggest";
include("inc/header.php"); ?>
<div class="section page"> <div class="wrapper"> <h1>Suggest a Media Item</h1> <?php if (isset($_GET["status"]) && $_GET['status'] == "thanks") { echo "<p>Thanks for the email! I’ll check out your suggestion shortly!</p>"; } else { ?> <p>If you think there is something I’m missing, let me know! Complete the form to send me an email.</p> <form method="post" action="suggest.php"> <table> <tr> <th><label for="name">Name</label></th> <td><input type="text" id="name" name="name" /></td> </tr> <tr> <th><label for="email">Email</label></th> <td><input type="text" id="email" name="email" /></td> </tr> <tr> <th><label for="name">Suggest Item Details</label></th> <td><textarea name="details" id="details"></textarea></td> </tr> </table> <input type="submit" value="Send" /> </form> <?php } ?> </div> </div>
<?php include("inc/footer.php"); ?>
5 Answers
Simon Coates
28,694 Points<input type="text" id="email" name="email" />
means that the value will show up as $_POST['email']. However,
$email = trim(filterinput(INPUT_POST,"name",Filter_SANITIZE_EMAIL));
looks for the value on $POST['name']. The first parameter for filterinput indicates whether you are using POST or GET, while the second indicates where to find the value you want. So you should probably use
$email = trim(filterinput(INPUT_POST,"email",Filter_SANITIZE_EMAIL));
which tries to get the value for $_POST['email']
Martina Carrington
15,754 PointsThanks Simon, :D Simon , how did you put the code in that format
Simon Coates
28,694 Pointsuse three backticks ` (on the key with the ~) before the code and after the code. try it out.
Simon Coates
28,694 Pointsfor starters, there's a problem with your use of filter_input. You've fed in 'name' on every variable.
Martina Carrington
15,754 PointsHey Simon Coates , i don't know how to put the codes that i posted in a different format
Martina Carrington
15,754 Pointsif($_SERVER["REQUEST_METHOD"] == "POST"){
$name = trim(filter_input(INPUT_POST,"name",Filter_SANITIZE_STRING));
$email = trim(filter_input(INPUT_POST,"name",Filter_SANITIZE_EMAIL));
$details = trim(filter_input(INPUT_POST,"name",Filter_SANITIZE_CHARS));
if ($name == ""|| $email == "" || $details == ""){
echo "Please fill in the required field: Name, Email and Details";
exit;
}
require("inc/phpmailer/class.phpmailer.php");
echo "<pre>";
$email_body = "";
Martina Carrington
15,754 PointsOMG!!!! cool , Thanks Simon
Simon Coates
28,694 PointsAt the section that says, "add an answer" can you see a link that says 'Markdown cheatsheet'?
Simon Coates
28,694 Pointsthat link should cover the basic syntax. I'd also note that php displays best if you include the opening <?php.
<?php
//this is a comment
echo "this is some php code";
should include some syntax highlighting.
Martina Carrington
15,754 Pointsyes, i see it
coskun olcucu
5,340 Points$pageTitle = "Suggest a Media Item";
$section = "suggest";
Simon Coates
28,694 PointsSimon Coates
28,694 PointsPeople are going to have an easier time reading your code if you use the syntax for displaying code. For treehouse, that seems to be the use of three backticks (on the key with the tilde on most keyboards) before and after code. On the line with the opening backticks, you can also follow these immediately with the language you are using, so that highlighting is applied. some operations (such as posting a comment) typically display with a link to a Markdown Cheatsheet that explains the syntax.