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

Nicole Berry
Nicole Berry
6,537 Points

Elseif conditioning not registering on the site

First of all Here's the code:

$role = "Stupid PHP";

if( USE_FULL_NAME == TRUE){ $name = $first_name . ' ' . $last_name; } else { $name = $first_name; }

if( $role = 'Artist'){ $info = "I draw a lot"; } elseif( $role == 'Stupid PHP'){ $info = "I really hate PHP right now"; } else { $info = "PHP sucks"; }

The issue I'm having is in the second if statement. As it look right now, I should see "I really hate PHP right now" when I click preview, but instead, "I draw a lot" appears on the site. I've rewritten the code several times now and I've tried copying the code in the video as much as I can. No matter what I do, it ignores the elseif statement. I can't figure out what I've done wrong.

2 Answers

Your typo is a very common one. Happens to all of us!! You have a = where you need ==. What your code is doing is assigning a String to $role, rather than asking if $role is 'Artist' It should be changed to this:

if( $role == 'Artist')
Nicole Berry
Nicole Berry
6,537 Points

I knew it was probably something really simple, but I couldn't find it for the life of me last night. Thank you!