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

contact-process.php

I am having some trouble identifying a syntax issue while coding the php code for the contact form. This is what my browser displays: Notice: Undefined index: name in B:\xampp\htdocs\shirts4mike\contact-process.php on line 5

Notice: Undefined index: email in B:\xampp\htdocs\shirts4mike\contact-process.php on line 6

Name: Email: Message:The is a message from me!

5 Answers

May i see you source code?

contact.php code: <?php $pageTitle = "Contact Mike"; $section = "contact"; include('inc/header.php'); ?>

<div class="section page">

    <div class="wrapper">

        <h1>Contact</h1>

        <p>I&rsquo;d love to hear from you! Complete the form to send me an email.</p>

        <form method="post" action="contact-process.php">

            <table>
                <tr>
                    <th>
                        <label for="name">Name</label>
                    </th>
                    <td>
                        <input type="text" id="name">
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="email">Email</label>
                    </th>
                    <td>
                        <input type="text" id="email">
                    </td>
                </tr>
                <tr>
                    <th>
                        <label for="message">Message</label>
                    </th>
                    <td>
                        <textarea name="message" id="message"></textarea>
                    </td>
                </tr>
            </table>
            <input type="submit" value="Send">

        </form>

    </div>

</div>

<?php include('inc/footer.php') ?>

contact-process.php code: <pre><?php

$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$email_body = "";
$email_body = $email_body . "Name: " . $name . "\n";
$email_body = $email_body . "Email: " . $email . "\n";
$email_body = $email_body . "Message: " .  $message;
echo("$email_body");

?></pre>

In your contact.php code you should the name attribute in your input fields like this <input type ="text name = "name" id="name"> This will enable the post array to reference the name input when you call the $_POST["name] function

In your contact.php code you should the name attribute in your input fields like this <input type ="text name = "name" id="name"> This will enable the post array to reference the name input when you call the $_POST["name] function

Like how? I don't your example on either post. Also, this is happening to the email section of the document too. I assume by applying your example would enable the $_POST["email"] as well? Thank you for your help greatly appreciated!

Yes so it would be <input type="text" id="email" name="email"> replace every text field that is like that and it should work

I understand but could you provide me an example?

what do you mean?

you wrote this on a reply: In your contact.php code you should the name attribute in your input fields like this This will enable the post array to reference the name input when you call the $_POST["name] function. You said "you should the name attribute in your input fields like this" but didn't provide the example. I am a beginner to Php so any help would be great.