advancedfuture Posted December 1, 2009 Share Posted December 1, 2009 So here is my delimma. I setup wildcard subdomains on my server. My subdomain format is county.state.mydomain.com I'm matching the subdomains against my database, to ensure it is a valid combo, if it isn't it should redirect to the main page 'www'. Problem is my if statement is not working as it should... if I enter lets say... ilovebats.ca.mydomain.com it runs the query no problem, but doesn't execute the header statement in my IF statement... which leads me to beleive i malformed the if statement. Any help would be appreciated. <?php //Get what subdomain we are on. strip the county and state variables //from the URL, and if it is www, set it to Orange County, CA include 'dbconnect.php'; $domain = explode('.',str_replace("mydomain.com"," ",$_SERVER['SERVER_NAME'])); $county = $domain[0]; $state = $domain[1]; //This variable is used for displaying the county without the slashes $county_slash = str_replace("-"," ",$county); //If we are on the root of the domain, set the variables to Orange County, CA if ($county == "www") { $county = "Orange"; $state = "CA"; } //Check to make sure subdomain is valid. If not redirect to www else { $query = "SELECT * FROM `zip_code` WHERE county='$county' AND state_prefix='$state'"; $results = mysql_query($query); if($results == 0) { header('LOCATION: http://www.mydomain.com'); exit; } } ?> Link to comment https://forums.phpfreaks.com/topic/183631-problem-with-if-statement/ Share on other sites More sharing options...
sasa Posted December 1, 2009 Share Posted December 1, 2009 if(mysql_num_rows($results)==0) Link to comment https://forums.phpfreaks.com/topic/183631-problem-with-if-statement/#findComment-969223 Share on other sites More sharing options...
advancedfuture Posted December 1, 2009 Author Share Posted December 1, 2009 Thanks Susa.. Works flawlessly now... Sometimes I forget some of the simple mysql functions. =] Link to comment https://forums.phpfreaks.com/topic/183631-problem-with-if-statement/#findComment-969227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.