g3mma111 Posted August 15, 2007 Share Posted August 15, 2007 Im fairly new to PHP and am having a problem with the following script: <? if ($gender='F') { ?> <img name="" src="/images/woman.jpg" width="101" height="140" alt=""> <? } else { ?> <img name="" src="/images/man.jpg" width="101" height="140" alt=""> <? } ?> I am trying to make it so that if gender is F then a woman pic gets displayed and otherwise it is a man one. Can anyone see where ive gone wrong? at the moment it just displays a woman pic regardless of what the gender is. Quote Link to comment https://forums.phpfreaks.com/topic/65015-solved-new-to-php-please-help-with-else/ Share on other sites More sharing options...
LiamProductions Posted August 15, 2007 Share Posted August 15, 2007 Hmm something like this: <?php if($gender == "F") { echo "your/image/file.gif"; } elseif ($gender == "M") { echo "your/image/file1.gif"; } else { echo "Your not a male or female!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65015-solved-new-to-php-please-help-with-else/#findComment-324461 Share on other sites More sharing options...
GingerRobot Posted August 15, 2007 Share Posted August 15, 2007 The reason for your error is because you were using the assignment operator (=) rather than the comparison operator (==) in your if statement: <? if ($gender='F') { ?> Should be: <? if ($gender=='F') { ?> Quote Link to comment https://forums.phpfreaks.com/topic/65015-solved-new-to-php-please-help-with-else/#findComment-324464 Share on other sites More sharing options...
g3mma111 Posted August 15, 2007 Author Share Posted August 15, 2007 thanks a lot - its working great. Quote Link to comment https://forums.phpfreaks.com/topic/65015-solved-new-to-php-please-help-with-else/#findComment-324465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.