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
Daniel Silva
10,644 PointsChange img with If statement in PHP
I'm trying to change a background image with PHP using and if statement depending on if the user selects "Male" or "Female". I tested it to see if it would change colors and it worked fine, but when I try to use background images instead the code doesn't run. Here it is: if($gender === "Male") { printf("<body style='background-img: url('../Images/logo2.png');'></body>"); }
As I said if I do background color, it works just fine, so I'm assuming that maybe the file path isn't referenced correctly?
1 Answer
Daniel Gauthier
15,000 PointsHey Daniel,
I just used your code example to create a small project and can say that you're almost certainly experiencing an issue with pathing.
One thing I did notice in your post is that you're backing up one level in your directory before going into the "Images" folder, which would be normal if you were pathing from a css file in a css folder, but if your code is in the root directory, then you may be going up one level out of habit. This would cause the parser to find itself in a directory that isn't even related to your project, and likely doesn't even have an "Images" folder.
Your desired effect worked on this side, so hopefully you figure out the pathing soon.
Good luck!