Page 1 of 1

if then else loop with $_GET fails

Posted: Tue Jun 14, 2005 6:05 am
by robster
question:

:)

Code: Select all

if ($get_we_are == "" || $get_post_code == "" || $get_username == "" || $get_email == "" || $get_bday_day == "" || $get_bday_month == "" || $get_bday_year == "" ||	$_GET['meeting_a_1'] == "" || $_GET['meeting_a_2'] == "" || $_GET['meeting_a_3'] == "" || $_GET['meeting_a_4'] == "" || $_GET['meeting_a_5'] == "" || $_GET['meeting_a_6'] == "" || $_GET['meeting_a_7'] == "" )
		{
			echo "<table width=\"50%\" border=\"0\" cellpadding=\"5\" cellspacing=\"10\" align=\"center\"><tr><td class=\"error_box\" align=\"center\">";
			echo "Attention!<br>You have not answered all the questions, please scroll down, look for the red errors and fill in those questions.<br>Thank you.";
			echo "</td></tr></table>";
		}
		else
		{
			echo "All checks passed, you can continue...<br>";
		}

It's mostly good, the variables ALL have more than just "" (blank), so the if should give the All checks passed message... But, it doesn't. Upon removing the $_GET's from the equation, so it's now this...

Code: Select all

if ($get_we_are == "" || $get_post_code == "" || $get_username == "" || $get_email == "" || $get_bday_day == "" || $get_bday_month == "" || $get_bday_year == ""
...then it works a treat. Is it my code (shown) or is it they $_GET's are written incorrectly?

I don't see what's wrong with the code, I think I've looked at it too long now (three days :()

Any advice appreciated :)

Rob

Posted: Tue Jun 14, 2005 6:27 am
by phpScott
try

Code: Select all

print_r($_GET);
befor your if statement to make sure that the $_GET variables do have content or are at least set

Posted: Tue Jun 14, 2005 6:32 am
by timvw
Btw, also consider that " " is different than "". Might want to use http://www.php.net/trim..

Posted: Tue Jun 14, 2005 6:50 am
by robster
the print_r($_GET); showed that all variables had data in them. (and none had only a space " ").

:| (shrug)

Posted: Tue Jun 14, 2005 7:52 am
by robster
I've just checked, double checked and tripple checked it but it's the same thing. The bit that I really don't understand, is why removing the $_GET ors (||'s), the thing works!?

ie, this works:

Code: Select all

print_r($_GET);
		
		if ($get_we_are == "" || $get_post_code == "" || $get_username == "" || $get_email == "" || $get_bday_day == "" || $get_bday_month == "" || $get_bday_year == "" )
		{
			echo "<table width=\"50%\" border=\"0\" cellpadding=\"5\" cellspacing=\"10\" align=\"center\"><tr><td class=\"error_box\" align=\"center\">";
			echo "Attention!<br>You have not answered all the questions, please scroll down, look for the red errors and fill in those questions.<br>Thank you.";
			echo "</td></tr></table>";
		}
		else
		{
			echo "All checks passed, you can continue...<br>";
		}
but I really do need to check for those other things. Would I have to stick them in variables using $_GET earlier on in the code (like I have with the other variables)? I can't see why that should have to happen, but I might just have to. Double coding, yeuck.

Posted: Tue Jun 14, 2005 7:59 am
by Syranide
verify the names of all variables, you could easily have put a "l" instead of "1" or so, if all really have some data, it cannot matter, the law of nature ;)

post your information from $_GET here and we can check.

Posted: Tue Jun 14, 2005 7:56 pm
by robster
Turns out, after havinga good squizz at it, it's this.... The variables are not ALL being sent, so say I have:

Code: Select all

if ($get_we_are == &quote;&quote; || $get_post_code == &quote;&quote; || $get_username == &quote;&quote; || $get_email == &quote;&quote; || $get_bday_day == &quote;&quote; || $get_bday_month == &quote;&quote; || $get_bday_year == &quote;&quote; ||    $_GET&#1111;'meeting_a_1'] == &quote;&quote; || $_GET&#1111;'meeting_a_2'] == &quote;&quote; || $_GET&#1111;'meeting_a_3'] == &quote;&quote; || $_GET&#1111;'meeting_a_4'] == &quote;&quote; || $_GET&#1111;'meeting_a_5'] == &quote;&quote; || $_GET&#1111;'meeting_a_6'] == &quote;&quote; || $_GET&#1111;'meeting_a_7'] == &quote;&quote; )
out of all those $_GET's the only one selected and posted may have been _2 or _6. You see, there are 7 possible options, so I am checking for ALL of them. If I say, post _2 and change my code to only check for _2 then it works.

So basically, having the check there breaks it.

Does that make sense? Any ideas? I would have thought that even if it wasn't sent that it would be fine and say, yeah, nothing there (as it wasn't even a variable that was posted).

Would anyone have any ideas? I'm kind of stumped now.
thanks :(

Posted: Tue Jun 14, 2005 8:16 pm
by robster
I'm going to research this code from our very own forum legend:

:)

http://timvw.madoka.be/programming/php/ ... ltiple.txt