Why does this massive if statement not work?

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
w35z0r
Forum Newbie
Posts: 17
Joined: Thu May 18, 2006 7:02 pm

Why does this massive if statement not work?

Post by w35z0r »

Code: Select all

if ($row['commonName'] != "" && $row['latinName'] != "" && $row['thumbNail'] != "" && $row['image'] != "" && $row['partOfPlant'] != "" && $row['origin'] != "" && $row['family'] != "" && $row['aroma'] != "" && $row['description'] != "" && $row['generalProp'] != "" && $row['specificCond'] != "" && $row['emotionalWB'] != "" && $row['blendsWW'] != "" && $row['options'] != "" && $row['price'] != "") {
what I was thinking: $row is set by a mysql_fetch_array(). I want to see if each field is filled, if so I want to tell the user that they are done.
what happens? this is part of a function I define inside of a whole file of functions. If this if statement is present, NONE of the functions work. They don't even give me any errors. The whole page... well... stalls. No output, nothing prints. error_reporting(E_ALL) told me nothing. The only reason I know that, amid a few hundred lines of other code, that its THIS line that does it, is because I commented it out. BAM, whole thing worked. (well, I did have to take care of the corresponding curly bracket '}' but other than that...)

So my question is: why does this not only not work, but screw up everything else?

I'm going to write this a different way, but I'm just interested as to why this happens. Thanks!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Why does this massive if statement not work?

Post by califdon »

w35z0r wrote: what I was thinking: $row is set by a mysql_fetch_array(). I want to see if each field is filled, if so I want to tell the user that they are done.
...
So my question is: why does this not only not work, but screw up everything else?

I'm going to write this a different way, but I'm just interested as to why this happens. Thanks!
Well, PHP is server side script, so it runs in the web server, to create the code that is sent to the browser. Is that the time you want this logic to be executed? If so, I'd suggest that you check what the values of all those fields actually ARE and print them out, for debugging purposes. Maybe some of them are NULL values, rather than empty strings?
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: Why does this massive if statement not work?

Post by WebbieDave »

Well, it's hard to analyze without seeing more code but that line is basically saying: if even one of these fields is blank, don't run the following code.
User avatar
Frozenlight777
Forum Commoner
Posts: 75
Joined: Wed May 28, 2008 12:59 pm

Re: Why does this massive if statement not work?

Post by Frozenlight777 »

is there an else statement in there, if there isn't just do an else "something is blank"... if there is an else and you're getting a blank white screen then you might be missing a semicolon or something
Post Reply