gschimek Posted October 10, 2010 Share Posted October 10, 2010 I'm pulling my hair out trying to figure out a simple problem. I've got the following PHP code in an HTML page: $shutoff_date = strtotime($wkend_start_date) - 259200; if ($shutoff_date > $todays_date) { $current_month = date("m");$current_year = date("y");$freshman_eligible = 0;if ($current_month >= 2 && $current_month <=7) { $freshman_eligible = 1; }if ($current_month <= 7) { $seniors = $current_year ; } else {$seniors = $current_year + 1; }$juniors = $seniors + 1;$sophomores = $seniors + 2;$freshman = $seniors + 3;echo "HTML Stuff blah, blah, blah";if ($freshman_eligible = 1) {echo "<option value=\"$freshman\">$freshman</option>";}} The last test to see if $freshman_eligible is equal to 1 is always testing true, and it's actually resetting $freshman_eligible to whatever I put inside the IF statement. No matter what the variable is set to previously, it will reset to whatever I test for in the last section, and hence always tests true. I thought maybe it was an issue with scope, but I'm not sure what the issue would be or how to resolve it. What am I missing??? Link to comment https://forums.phpfreaks.com/topic/215523-if-statement-always-testing-true/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 10, 2010 Share Posted October 10, 2010 One = sign is an assignment operator and the result of assigning 1 to a variable, is always TRUE. Two == signs is a comparison operator. Link to comment https://forums.phpfreaks.com/topic/215523-if-statement-always-testing-true/#findComment-1120706 Share on other sites More sharing options...
gschimek Posted October 10, 2010 Author Share Posted October 10, 2010 I knew it was something simple. Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/215523-if-statement-always-testing-true/#findComment-1120720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.