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) Listing and Sorting Inventory Items Displaying Item Details

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

Unable to see the details page in browser.

I don't know, where did I make mistake. I am unable to view the details page in the browser. I watched the tutorial video, but couldn't know that what was the mistake. I am pasting the details.php below. Please help....

<?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>

Simon Coates
Simon Coates
28,694 Points

can you post a link to a snapshot of your workspace?

Simon Coates
Simon Coates
28,694 Points

fyi, you can get code to display correct if you put three backticks (which are on the key with the ~) on a line before your code and three on a line after your code. Makes it easier for others to help you.

Simon Coates
Simon Coates
28,694 Points

you should be able to get code by skipping ahead a video or two and going to the downloads tab. Whereas some courses let you download all code in a single download, i think Alana might put the complete code for a challenge on the next video.

2 Answers

Shane Oliver
Shane Oliver
19,977 Points

No problem. In PHP there is a more clear syntax for writing conditionals, it let's you see which level you are closing

if( condition ) :
    //your code
endif;
AVINASH KUMAR
seal-mask
.a{fill-rule:evenodd;}techdegree
AVINASH KUMAR
Front End Web Development Techdegree Student 8,110 Points

My suggest.php is not working. Shane, can you please check the below pasted code.

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

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

Hi Shane..

Presently 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 lot of time in finding the mistake.

So can you please provide me the completed project file of "Integrating PHP with databases" course.

Thank you.

Shane Oliver
Shane Oliver
19,977 Points

You are aren't closing your conditionals properly - you are just jumping into the next condition without closing the previous