iBlizz Posted April 18, 2009 Share Posted April 18, 2009 Code is below...2 if statements. Based on what the $searchType variable is. However, it doesn't matter, both blocks of code execute. $searchType echos "state" however the block in if $searchType="country" executes as well. Vice versa when searchType is country, state also executes. I'm just learning PHP, but I'm pretty sureI have if statements down...I'm puzzled at this though. echo $searchType; if ($searchType = "state") { echo "Searching by state"; mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $ambassadors = mysql_query("SELECT * FROM ambassadors WHERE state='$searchValue'") or die(mysql_error()); while ($ambassador = mysql_fetch_array($ambassadors)) { echo "<tr><td>"; echo "<iframe src=\"http://gamercard.xbox.com/" . $ambassador['gamertag'] . ".card\" scrolling=\"no\" frameBorder=\"0\" height=\"140\" width=\"204\">" . $ambassador['gamertag'] . "</iframe>"; echo "</td><td>"; $stateSearch = mysql_query("SELECT state FROM state WHERE id='$searchValue'") or die(mysql_error()); while ($state = mysql_fetch_array($stateSearch)) { echo $state['state']; } echo "</td></tr>"; } } if ($searchType = "country") { echo "Searching by country"; mysql_connect($host, $dbuser, $dbpass) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $ambassadors = mysql_query("SELECT * FROM ambassadors WHERE country='$searchValue'") or die(mysql_error()); while ($ambassador = mysql_fetch_array($ambassadors)) { echo "<tr><td>"; echo "<iframe src=\"http://gamercard.xbox.com/" . $ambassador['gamertag'] . ".card\" scrolling=\"no\" frameBorder=\"0\" height=\"140\" width=\"204\">" . $ambassador['gamertag'] . "</iframe>"; echo "</td><td>"; $countrySearch = mysql_query("SELECT country FROM country WHERE id='$searchValue'") or die(mysql_error()); while ($country = mysql_fetch_array($countrySearch)) { echo $country['country']; } echo "</td></tr>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/154669-solved-why-is-my-if-statement-not-working/ Share on other sites More sharing options...
The Little Guy Posted April 18, 2009 Share Posted April 18, 2009 because you are assigning "state" to $searchType if ($searchType = "state") { if ($searchType = "country") { You will want to do a comparison, like this (two equal signs): if ($searchType == "state") { if ($searchType == "country") { Link to comment https://forums.phpfreaks.com/topic/154669-solved-why-is-my-if-statement-not-working/#findComment-813337 Share on other sites More sharing options...
iBlizz Posted April 18, 2009 Author Share Posted April 18, 2009 Hot damn! Thanks so much man. Learned sometime new. Comparison != Assignment (haha) thanks man. Link to comment https://forums.phpfreaks.com/topic/154669-solved-why-is-my-if-statement-not-working/#findComment-813339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.