Similar conditions differ in their result

Before I go totally bald pulling my hair out does anyone have a clue why


if(!$_POST['catid'] || !$_POST['imgno']) {

	exit ('<h2 id="message">You must select an amount AND a gallery name to add images.</h2>
	<p><a id="homelink" href="admin.php">Return to Administration Home.</a></p>
');
	
}else{

works and


if(!$_POST['catid']) {

	exit ('<h2 id="message">You must select a gallery name to delete images.</h2>
	<p><a id="homelink" href="admin.php">Return to Administration Home.</a></p>');

}else{

cruelly decides to go onto what I’d rather it didn’t?

A big thankyou to sanity savers.

My guess is the problem is somewhere else in your code.

soooo I solved it, but I’d like to know why there was a problem.

I have four things a user can do on this admin homepage. Each requires the selection of a category from a generated list. ( I rather redundantly, I think, made separate calls to the database for each identical list but anyway…).

On submission the forms post a ‘catid’ as can be seen from the original problem above. I solved this by changing the form name to ‘catid2’.

Why did I have to do this when each form can only be used separately?

Actually this has not solved the problem. Now I get the error message when no category has been selected and even when one has.

Back to the drawing board.

I would suggest you just echo the $_POST array
just add print_r($_POST) and see what’s in it.
Also, do you have any catid with value of 0?
Or maybe you submit form with GET instead of POST?

Thanks for the print_r($_POST), I’d never used that before. Unfortunately it made me scratch my head even more because what was supposed to be posted was posted.

In the end changing names and variables was a waste of time. This was another example of keeping an eye out for the most seemingly harmless detail.

The empty values in my select list (ie “Choose One” and “-------”) had spaces between the quotation marks. So I overlooked the fact that " " is a very different thing to “”.

Thanks for the tips, I feel so stupid.

btw- var_dump() is very handy for inspecting string values. The number you see next to the quoted string is the number of bytes the string is. This makes it easy to get a better idea of what the strings contents are. For example, low visibility, non visible, and multibyte characters are usually pretty obvious when you see the string quoted along with the length in bytes.

Thanks for that, crmalibu.