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 Build a Basic PHP Website (2018) Adding a Basic Form Checking the Request Method

AVINASH KUMAR
seal-mask
.a{fill-rule:evenodd;}techdegree
AVINASH KUMAR
Front End Web Development Techdegree Student 8,110 Points

suggest.php is not working..

<?php if ($_SERVER["REQUEST_METHOD] == "POST") { $name = $_POST["name"]; $email = $_POST["email"]; $details = $_POST["details"];

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! 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="details">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"); ?>

3 Answers

simhub
simhub
26,543 Points

hi Avinash,
you can take a look at my snapshot

https://w.trhou.se/dkfbi4djjr

AVINASH KUMAR
seal-mask
.a{fill-rule:evenodd;}techdegree
AVINASH KUMAR
Front End Web Development Techdegree Student 8,110 Points

Hi simhub

I am pursuing the "Integrating PHP with databases" course. Again and again I am stuck at different points in the course. And it takes a long time in finding the mistake in the code.

Can you please provide me the completed project file of the "Integrating PHP with database" course.

Thank you..

simhub
simhub
26,543 Points

hi Avinash,

i think it's just a typo.

try this:

/**
 * $_SERVER not $SERVER - (missing[ _ ])
 * ["REQUEST_METHOD"] not ["REQUEST_METHOD] - (missing[ " ])
 */
if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST["name"]; $email = $POST["email"]; $details = $_POST["details"];

everything else is fine :)

AVINASH KUMAR
seal-mask
.a{fill-rule:evenodd;}techdegree
AVINASH KUMAR
Front End Web Development Techdegree Student 8,110 Points

There is underscore character before the SERVER and between the REQUEST_METHOD in my suggest.php file. I don't know, how did it go missing after i pasted the file. Still the suggest.php is not working. Please help, simhub!!

AVINASH KUMAR
seal-mask
.a{fill-rule:evenodd;}techdegree
AVINASH KUMAR
Front End Web Development Techdegree Student 8,110 Points

Also, the "for" word is looking different (in blue color text) in notepad++ in the below mentioned sentence of the file.

<?php if (isset($_GET["status"]) && $_GET["status"] == "thanks") { echo "<p>Thanks for the email! I’ll check out your suggestion shortly!</p>"; }

How about the apostrophe in the word "I'll"? Alena replaces it with &rsquo in her code. In which cases does this cause problems?