Ordering the if statements
Posted: Thu Aug 06, 2009 5:15 am
Hey guys, i'm new to this board, so sorry if this is the wrong place to post the question.
My problem is that I have a bunch of IF statements I just can't get in the correct order.
I have tried several different combinations that I think make sense.
The order intends to go through all the if statements and then if they all pass, finally execute the mysql query.
If you could help, I would really appreciate it, thankyou
My problem is that I have a bunch of IF statements I just can't get in the correct order.
I have tried several different combinations that I think make sense.
The order intends to go through all the if statements and then if they all pass, finally execute the mysql query.
If you could help, I would really appreciate it, thankyou
Code: Select all
if (!empty($_POST))
{
if(!$subject || strlen($subject = trim($subject)) == 0)
echo "Subject not entered";
else if(!$comment || strlen($comment = trim($comment)) == 0)
echo "Comment not entered";
else if(!$comment || strlen($comment = trim($comment)) < 10)
echo "Comment too short, must be 10 characters at least";
else if (isset ($_FILES['new_image']))
{
$imagename = $subject . '.jpg';
$source = $_FILES['new_image']['tmp_name'];
$target = "images/news/".$imagename;
$file = explode('.', $source);
$ext = end($file);
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "images/news/" . $imagepath; //This is the new file you saving
$file = "images/news/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 150;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "images/news/sml_" . $imagepath; //This is the new file you saving
$file = "images/news/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 80;
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
}
else if ($ext !== 'jpg' || $ext !== 'jpeg')
echo 'Your file must be a jpeg';
else if (!$comment || strlen($comment = trim($comment)) > 10)
{
echo "".$_SESSION['username'].", you have added a news piece";
mysql_query($query);
}
}