First off, please use php tags, not code tags.
All of your if statements will NEVER fire. They are all (of course except for the first one) preceeded by else. So at most one of the if blocks will ever run.
// Run whenever condition 1 is true
if (condition 1) {
}
/* will NEVER happen. i.e. will only happen when the condition in the if statement
above is not true (due to the "else"), and since I'm reusing the same codintion here...
this part will always be false if it's actually evaluated. */
ELSE if (condition 1) {
}
/* If both condition 1 and condition 2 are true, this will NOT run.
Only happens if condition 1 is false AND condition 2 is true. */
else if (condition 2) {
/* Runs if 2.1 is true AND 2 is true AND 1 is false */
if (condition 2.1)
}
/* (half of) This condition will be evaluated regardless of what happened above,
since there is no preceeding else) */
if (true || ("the boolean value of this part is NEVER evaluated") ) {
}
if (false && ("the boolean value of this part is NEVER evaluated") ) {
}
/* You can easily check the validity of my claim for the last two statements above.
Do note the ; right after the if statements. Wether the condition is true or not,
no code is actually run.
My point is not wether or not echo runs (it always does), but that the last half
of the conditions are not evaluated. */
$i = 1;
if (true || ($i = 'This will not be assigned to $i'));
echo $i;
if (false && ($i = "Still no value assignment"));
echo $i;
With this in mind, over to your code...
// $ext is ONLY defined if $_FILES[...] is set
else if (isset ($_FILES['new_image'])) {
$ext = end($file);
}
/* If the above if statement is true, this one will NEVER be evaluated, due to the else.
If the above was false, so that this one is actually evaluated, it will ALWAYS be true,
since $ext is not yet defined. */
else if ($ext !== 'jpg' || $ext !== 'jpeg')
echo 'Your file must be a jpeg';
And there are more oddities
/* There are two possibilities here:
1. comment is false, and of unspecified type,
which means any of the following values:
0, "0", "", false
or it is undefined (which also raises an E_NOTICE)
2. comment is none of the above (or the second part would never be evaluated,
so not counting leading/trailing whitespaces, it contains 0 characters. */
else if(!$comment || strlen($comment = trim($comment)) == 0)
echo "Comment not entered";
/* If this is evaluated, we know that none of the above conditions were true,
so !$comment is always false. Hence, it adds nothing but confusion.
This means ONLY the second part can be true. Moreover, ANY time the above
is true, this will also be true.
The reverse does not hold however. So, you might just as well remove the
above if statement instead. Telling the user that they must post a comment of
at least 10 characters should be enough. */
else if(!$comment || strlen($comment = trim($comment)) < 10)
In the end, the query will never run if the user posts a file. And once again we see !$comment, which as explained above is always false here. So the only time this could run, is if the comment is indeed more than 10 characters long. Except it won't ever, as explain above.