php help

jhogeterp

Registered
okay this must be something very simple, but I am just starting to learn php and can't figure out why this:

<?php
if (!$table_name) || (!$num_fields)) {
header("location: .../admin/createtable.html");
exit;
}
?>

produces this error:

Parse error: parse error, unexpected T_BOOLEAN_OR in /fielddef.php on line 2
 
Well, my guess is because you are missing a parenthesis in your if statement. You have 2 open and 3 close.

Try changeing the code to this:
PHP:
<?
if( (!$table_name) || (!$num_fields) ){
...
}
?>
If that doesn't fix the issue (aka. you just made a typo on the forum) let me know and I will investigate further.
 
I tried it, and It didn't work. What I am doing actually, is following examples on a book, so I would think that they should work. I have gone over it many times, and keep getting the parse error. Any help would be greatly appreciated. thanks!
 
What exactly are you trying to accomplish with that negated conditional statement? Can you write it out in English?

EDIT: The reason I ask is that those "Unexpected T-blah blah" is usually a typecast error, or a misplaced quotation (which bleeds lines of code together in a way PHP doesn't recognize).

That error message leads me to believe that those two variables are not boolean.

If you want to see if they have values, you need to if (!isset($variable)) {} ...
 
you do have a parse error here...

PHP:
if (!$table_name) || (!$num_fields)) {

Gnomo is right on this one. With the above code you don't have matching parens. Gnomo suggested putting a paren after the if to match that double paren you have after num_fields. make sure you didn't just add a paren to both ends after reading his suggestion.

to my knowledge, there is no "boolean" type in php. types are automagically converted to meet the current needs. this statement should work, but you have to get the syntax right.
 
php handles it like so (i think)...

for numbers, 0 is false and anything is true. i could be wrong about negatives, but i'm pretty sure.

for anything is it is more a case of if it is defined at all it is true. otherwise false. i believe the empty string is false, but an 'a' is true.

someone can check me on that, but i'm pretty sure thats how it goes.
 
It looks like that is the case for strings as well. I'm still wondering on the purpose of the statement though...

PS: I assume the Header directive's ".../" is just to sace space? You can't really reference anything with three periods as far as I know, so you'll solve this problem and get an error there hehe.
 
Back
Top