if then else loop with $_GET fails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

if then else loop with $_GET fails

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Btw, also consider that " " is different than "". Might want to use http://www.php.net/trim..
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

the print_r($_GET); showed that all variables had data in them. (and none had only a space " ").

:| (shrug)
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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.
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post 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.
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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 :(
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

I'm going to research this code from our very own forum legend:

:)

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