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

WordPress How to Build a WordPress Plugin Building a WordPress Plugin Settings Page Working with Forms in a WordPress Plugin Settings Page

Bob Sutherton
Bob Sutherton
20,160 Points

Does anyone know what's wrong with this code?

It gives me the white screen of death. But when I take it out the site works again. What's wrong with this code that is so bad? I thought I copied it just like Zac Gordon and placed where he did. What's up?

if( isset( $_POST['wptreehouse_form_submitted'] ) ) {

        $hidden_field = esc_html( $_POST['wptreehouse_form_submitted'] );

        if( $hidden_field == 'Y' ) {

            wptreehouse_username = esc_html( $_POST['wptreehouse_username'] );

            echo $wptreehouse_username;

            }
        }

7 Answers

<?php
if( isset( $_POST['wptreehouse_form_submitted'] ) ) {

        $hidden_field = esc_html( $_POST['wptreehouse_form_submitted'] );

        if( $hidden_field == 'Y' ) {

            $wptreehouse_username = esc_html( $_POST['wptreehouse_username'] );

            echo $wptreehouse_username;

            }
        }
?>

Compare your code with the one I posted. You don't have to insert that line anywhere, just edit your code to define the variable.

$wptreehouse_username = esc_html( $_POST['wptreehouse_username'] );

It looks like you haven't defined your wptreehouse_username as being a variable.

The problem there isn't really addressed in the video, but if you want to fix the problem, you can't use an OR (||) operator. Change that to an AND (&&) operator.

Example:

<?php if( isset($wptreehouse_username) || $wptreehouse_username != '' ): ?>

This code says if $wptreehouse_username is set OR it's NOT blank, then load the profile. I suppose $wptreehouse_username is set (to blank), so the first criteria is met and the code loads Mike's profile.

On the other hand:

<?php if( isset( $wptreehouse_username) && $wptreehouse_username != '' ): ?>

This code says IF $wptreehouse_username IS set AND it's NOT blank, then load the profile.

Hope this helps.

Bob Sutherton
Bob Sutherton
20,160 Points

Thanks for the reply! He actually ends up addressing it in a later video.

Bob Sutherton
Bob Sutherton
20,160 Points

Cool, where does this line go? I don't remember Zac mentioning this one.

Bob Sutherton
Bob Sutherton
20,160 Points

Doh! Let me try that out. Thanks!

Bob Sutherton
Bob Sutherton
20,160 Points

It worked, thanks! I'm always getting tripped up by little small stuff like that. And here I thought I had analyzed my code alongside Zac's and somehow I overlooked it.

It happens to all of us, don't beat yourself up too much. The more you practice, the less frequent your mistakes will be.

Bob Sutherton
Bob Sutherton
20,160 Points

What do you think is wrong with this one here? Mike the Frog is not supposed to appear when I save it as blank but he does anyway.

<?php if( isset($wptreehouse_username) || $wptreehouse_username != '' ): ?>

                    <div class="postbox">

                        <h3><span>Mike the Frog's Profile</span></h3>
                        <div class="inside">

                            <p><img width="100%" class="wptreehouse-gravatar" src="<?php echo $plugin_url . '/images/mike-the-frog.png'; ?>" alt="Mike the Frog Gravatar"></p>

                            <ul class="wptreehouse-badges-and-points">                          

                                <li>Badges: <strong>200</strong></li>
                                <li>Points: <strong>10000</strong></li>

                            </ul>
                        </div> <!-- .inside -->
                    </div> <!-- .postbox -->

                    <?php endif; ?>