Jump to content

else being ignored?


Serenitee

Recommended Posts

It would see my else is being ignored, and it's a bit confusing.  There is only 1 row in my current test array, and $craftItAmt == 'm' at the moment.  The result "should" be that it goes into the else and moves off to the error page with code e041 - but instead it is ignoring the else, and returning error page with e001 as the array is empty.  I'm stumped, if I change the redirect to an echo, it will echo.  If I change the redirect to a variable set (ie: $intCheck = 'yes';) and then place an if $intCheck == 'yes' go to the header.. it is still ignored.

 

$toCraft = array();
foreach($clean as $craftIt => $craftItAmt)
{if($craftItAmt != '')
	{if(is_numeric($craftItAmt))
		{$toCraft[str_replace('_', ' ', $craftIt)] = $craftItAmt;}
	else
		{header('Location: /crafted/error.php?Code=e041');}}
}

$toCraftCounter = count($toCraft);

if($toCraftCounter == 0)
{header('Location: /crafted/error.php?Code=e001');}

 

tia

 

Link to comment
https://forums.phpfreaks.com/topic/209482-else-being-ignored/
Share on other sites

You need exit; statements after each header() redirect to prevent the remainder of the code on the page from executing while the browser requests the new URL that is in the Location: header.

 

The last header() your code is outputting WINS.

Link to comment
https://forums.phpfreaks.com/topic/209482-else-being-ignored/#findComment-1093782
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.