Page 1 of 1

Why does this massive if statement not work?

Posted: Thu Jun 19, 2008 1:31 pm
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!

Re: Why does this massive if statement not work?

Posted: Thu Jun 19, 2008 1:46 pm
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?

Re: Why does this massive if statement not work?

Posted: Thu Jun 19, 2008 2:17 pm
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.

Re: Why does this massive if statement not work?

Posted: Thu Jun 19, 2008 2:23 pm
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