pneudralics Posted October 30, 2008 Share Posted October 30, 2008 I want to be able to check my nested if statements to see if it's true or false. How would I write that? EXAMPLE if (this is true and the 2nd if is true){ } else { } if (the first if is true){ } else { do this if the first is not true } Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/ Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678460 Share on other sites More sharing options...
pneudralics Posted October 30, 2008 Author Share Posted October 30, 2008 Is there a way to assign an if statement to some kind of variable? Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678463 Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 What do you mean? Please explain. Ken Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678467 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 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 '; } } Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678494 Share on other sites More sharing options...
predator12341 Posted October 30, 2008 Share Posted October 30, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678499 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 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; } } } Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678509 Share on other sites More sharing options...
predator12341 Posted October 30, 2008 Share Posted October 30, 2008 from what i am understanding i think he wants to be able to right an if inside an if(if(blah<blah){return 1;}){echo "yeah";} Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678516 Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 Until the OP explains what he wants, we're all just guessing. Ken Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678517 Share on other sites More sharing options...
predator12341 Posted October 30, 2008 Share Posted October 30, 2008 to true kenrbnsn. Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678521 Share on other sites More sharing options...
Maq Posted October 30, 2008 Share Posted October 30, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678522 Share on other sites More sharing options...
predator12341 Posted October 30, 2008 Share Posted October 30, 2008 "Is there a way to assign an if statement to some kind of variable?" now that is what makes me believe he wants a return from his if statements (but not have the if in a function) that could be done like so if(a < b) { $AA = 1; } else { $AA = 0; } Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-678527 Share on other sites More sharing options...
pneudralics Posted October 31, 2008 Author Share Posted October 31, 2008 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 (); } Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-679315 Share on other sites More sharing options...
predator12341 Posted October 31, 2008 Share Posted October 31, 2008 what error you getting with the script because just having a quick skim though it and it seems alrite Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-679404 Share on other sites More sharing options...
kenrbnsn Posted October 31, 2008 Share Posted October 31, 2008 This statement <?php if ($thumbnailimagecheck = true) { ?> should be either <?php if ($thumbnailimagecheck == true) { ?> or <?php if ($thumbnailimagecheck) { ?> Use one "=" for assignment and two "==" for comparison. Ken Quote Link to comment https://forums.phpfreaks.com/topic/130736-solved-how-do-i-make-my-if-statement-true-or-false/#findComment-679416 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.