Jump to content

[SOLVED] How do I make my if statement true or false?


pneudralics

Recommended Posts

Just like your pseudo code:

<?php
if ($first && $second) {
   echo 'Both $first & $second are true<br>';
} else {
   if ($first) {
       echo '$first is true, but second is false<br>';
   } else {
       echo 'Both $first & $second are false<br>';
   }
}
?>

 

Ken

Link to comment
Share on other sites

if ($first=="abc" && $second=="efg") {
   echo 'Both $first & $second are true
';
   } else {
   if ($first=="abc") {
      echo '$first is true, but second is false
';
   } else {
      echo 'Both $first & $second are false
';
   }
}

Link to comment
Share on other sites

i think he is talking about getting a return from the if statement as you can do with functions. if that is the case why would you want to do that?

 

There are many reasons why you would want to do that.  First of all you should have a variable for the return.  Something like:

 

function getNumber($first, $second) 
{
if ($first=="abc" && $second=="efg") {
   echo 'Both $first & $second are true
';
   return 1;
   } else {
   if ($first=="abc") {
      echo '$first is true, but second is false
';
   return 4;
   } else {
      echo 'Both $first & $second are false
';
      return 3;
   }
}
}

 

 

Link to comment
Share on other sites

from what i am understanding i think he wants to be able to right an if inside an if(if(blah

 

kenrbnsn is right, we're all wasting our time guessing as to what the OP exactly wants.

 

Is there a way to assign an if statement to some kind of variable?

 

huh?

Link to comment
Share on other sites

Sorry I was kind of busy and didn't have time to respond. I'm trying to write a code for uploading an image and thumbnail. I tried nesting bunch of if statements but I can't seem to get it to work.

 

I want to have it where if the thumbnail image doesn't upload I don't want the main image to upload either vice versa. I'm trying to see if I can make an if statement true or false so it can check it before it uploads. My problem is I can't get the thumbnail to check to not upload if the main does not upload. When I nested it and the main image uploads it go on to the next if which is the thumbnail image and it won't be able to check anymore since it's already completed.

 

//Set main image, thumbnail and writing image name to database to true
$mainimagecheck = true;
$thumbnailimagecheck = true;
$databaseimagecheck = true;

//Check for main image
if ($thumbnailimagecheck = true) {
if ($mainimagecheck) {
	if (move_uploaded_file ($_FILES['image']['tmp_name'], GALLERYUPLOAD."$newname2")) {
		echo '<font color="red">Main image uploaded successfully.</font><br />';
	} 
} else {
	echo '<font color="red">Problem uploading main image.</font><br />';
}
} else {
echo '<font color="red">Main image didn\'t upload because thumbnail image didn\'t upload.</font><br />';
exit (); 
}
//Check for thumbnail image
if ($mainimagecheck = true) {
if ($thumbnailimagecheck) {
	if (move_uploaded_file ($_FILES['timage']['tmp_name'], GALLERYTHUMBNAILUPLOAD."$newname2")) {
		echo '<font color="red">Thumbnail image uploaded successfully.</font><br />';
	} 
} else {
	echo '<font color="red">Problem uploading thumbnail image.</font><br />';
}
} else {
echo '<font color="red">Thumbnail image didn\'t upload because main image didn\'t upload.</font><br />';
exit ();
}
//End image upload
//If inputs empty do not load the database
if ($mainimagecheck && $thumbnailimagecheck) {
if	(mysql_query("INSERT INTO gallery (image) VALUE ('$newname2')")) {
	echo '<font color="red">The images have been written to the database successfully.</font><br /><br />';
} else {
	echo '<font color="red">Images did not write to the database.</font><br /><br />';
}
} else {
echo '<font color="red">Images did not write to the database because main or thumbnail didn\'t upload.</font><br /><br />';
exit ();
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.