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 Working with Post Variables

Notice: Undefined index: name in /home/treehouse/workspace/process.php on line 3

I dont know what wrong suggest.php

<?php 
$pageTitle = "Suggest a Media Item";
$section = "suggest";

include("inc/header.php"); ?>

<div class="section page">
  <div class="wrapper" >
     <h1>Suggest a Media Item</h1>
     <p>If you think there is something I&rsquo;m missing, let me know! Complete the form to send me an email.</p>
      <form mehthod="post" action="process.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">Details</label></th>
          <td><textarea name="details" id="details"></textarea>
          </td>
          </tr>
        </table>
        <input type="submit" value="Send" />
      </form>
    </div>
</div>
<?php include("inc/footer.php"); ?>

process.php

<?php
$_POST= array();
$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 "</pre>";
?>

2 Answers

Simon Coates
Simon Coates
28,694 Points

to begin with

mehthod="post"

should be:

method="post"

if the method is messed up, then $_POST might not have any values.

thanks

Giuseppe Ardito
Giuseppe Ardito
14,130 Points

I had the same issue and I found this:

$ _POST or $ _GET are two special PHP functions that are used to get variables from a user-filled form. While using these functions, a user may encounter an error, stating that there is an undefined index.

This error can be avoided with the help of PHP isset ().

N.B. Undefined index is a minor error and is, therefore, not usually notified by default. Still, this depends on the server's configuration. With the help of the error_reporting function, the type of error reported can be changed.

I hope it helps!