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

I got this popup when I tried to submit to my form.

Fatal error: Uncaught Error: Call to undefined function filter_imput() in /home/treehouse/workspace/suggest.php:4 Stack trace: #0 {main} thrown in /home/treehouse/workspace/suggest.php on line 4

Here is my suggest.php

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = trim(filter_imput(INPUT_POST,"name",FILTER_SANITIZE_STRING)); $email = trim(filter_imput(INPUT_POST,"email",FILTER_SANITIZE_EMAIL)); $details = trim(filter_imput(INPUT_POST,"details",FILTER_SANITIZE_SPECIAL_CHARS));

if ($name == "" || $email == "" || $details == "") { echo "Please fill in the required fields: Name, Email and Details"; exit; } if ($_POST["address"] != "") { echo "Bad form input"; exit; }

require("inc/phpmailer/class.phpmailer.php");

$mail = new PHPMailer;

if (!$mail->ValidateAddress($email)) { echo "Invalid Email Address"; exit; }

$email_body = ""; $email_body .= "Name " . $name . "\n"; $email_body .= "Email " . $email . "\n"; $email_body .= "Details " . $details . "\n";

$mail->setFrom($email, $name); $mail->addAddress('treehouse@localhost', 'Alena'); // Add a recipient

$mail->isHTML(false); // Set email format to HTML

$mail->Subject = 'Personal Media Library Suggestion from ' . $name; $mail->Body = $email_body;

if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } 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&rsquo;m missing, let me know! Complete the form to 

send me and 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">Suggest Item Details</textarea></td> </tr> <tr style="display:none"> <th><label for="address">Address</label></th> <td><input type="text" id="address" name="address" /></td> <p>Please leave this field blank</p> </tr> </table> <input type="submit" value="Send" /> </form> <?php } ?> </div> </div>

<?php include("inc/footer.php"); ?>

my index.php

<?php include("inc/data.php"); include("inc/functions.php");

$pageTitle = "Personal Media Library"; $section = null;

include("inc/header.php"); ?> <div class="section catalog random">

        <div class="wrapper">

            <h2>May we suggest something?</h2>

    <ul class="items">
        <?php
        $random = array_rand($catalog,4);
        foreach ($random as $id) {
            echo get_item_html($id,$catalog[$id]);
        }
        ?>                          
            </ul>

        </div>

    </div>

<?php include("inc/footer.php"); ?>

my details.php

<?php include("inc/data.php"); include("inc/functions.php");

if (isset($_GET["id"])) { $id = $_GET["id"]; if (isset($catalog[$id])) { $item = $catalog[$id]; } }

if (!isset($item)) { header("location:catalog.php"); exit; }

$pageTitle = $item["title"]; $section = null;

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

<div class="section page">

<div class="wrapper">

    <div class="media-picture">

    <span>
        <img src="<?php echo $item["img"]; ?>" alt="<?php echo $item["title"]; ?>" />
    </span>

    </div>

    <div class="media-details">
        <h1><?php echo $item["title"]; ?></h1>
        <table>
            <tr>
                <th>Category</th>
                <td><?php echo $item["category"]; ?></td>
            </tr>
            <tr>
                <th>Genre</th>
                <td><?php echo $item["genre"]; ?></td>
            </tr>
            <tr>
                <th>Format</th>
                <td><?php echo $item["format"]; ?></td>
            </tr>
            <tr>
                <th>Year</th>
                <td><?php echo $item["year"]; ?></td>
            </tr>
            <?php if(strtolower($item["category"]) == "books") { ?>
            <tr>
                <th>Authors</th>
                <td><?php echo implode(", ",$item["authors"]); ?></td>
            </tr>
            <tr>
                <th>Publisher</th>
                <td><?php echo $item["publisher"]; ?></td>
            </tr>
            <tr>
                <th>ISBN</th>
                <td><?php echo $item["isbn"]; ?></td>
            </tr>
            <?php } else if(strtolower($item["category"]) == "movies") { ?>
            <tr>
                <th>Director</th>
                <td><?php echo $item["director"]; ?></td>
            </tr>
            <tr>
                <th>Writers</th>
                <td><?php echo implode(", ",$item["writers"]); ?></td>
            </tr>
            <tr>
                <th>Stars</th>
                <td><?php echo implode(", ",$item["stars"]); ?></td>
            </tr>
            <?php } else if(strtolower($item["category"]) == "music") { ?>
            <tr>
                <th>Artist</th>
                <td><?php echo $item["artist"]; ?></td>
            </tr>
            <?php } ?>
        </table>
    </div>

</div>

</div>

catalog.php

<?php include("inc/data.php"); include("inc/functions.php");

$pageTitle = "Full Catalog"; $section = null;

if (isset($_GET["cat"])) { if ($_GET["cat"] == "books") { $pageTitle = "Books"; $section = "books"; } else if ($_GET["cat"] == "movies") { $pageTitle = "Movies"; $section = "movies"; } else if ($_GET["cat"] == "music") { $pageTitle = "Music"; $section = "music"; } }

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

<div class="section catalog page">

<div class="wrapper">

    <h1><?php 
    if ($section != null) {
        echo "<a href='catalog.php'>Full Catalog</a> &gt; ";
    }
    echo $pageTitle; ?></h1>

    <ul class="items">
        <?php
        $categories = array_category($catalog,$section);
        foreach ($categories as $id) {
            echo get_item_html($id,$catalog[$id]);
        }
        ?>
    </ul>

</div>

</div>

<?php include("inc/footer.php"); ?>

2 Answers

Hi Aaron,

I think you are using filter_imput instead of filter_input.

The error points you in this direction by telling you that the function you're attempting to call, filter_imput(), is undefined (doesn't exist).

Thank-you! I got it to work now. It's amazing that it is something simple like that and that I didn't see it.