cloudll Posted June 25, 2015 Share Posted June 25, 2015 Hey people. Firstly, sorry if my Topic Title is incorrect. I wasn't 100% sure how to word it. In my code below, I have an if statement within an if statement. I have an }else{ set for one of the ifs, but I would like an }else{ for the other one. I just cannot get it working. I have tried placing it everywhere I can think of. Is it possible to have an else for this line if (($attackverify == "yes") && ($status == "online")) Here is my code. <?php // HANDLE THE ATTACK if (($attackverify == "yes") && ($status == "online")) { if (!isset($_SESSION['LAST_ATTACK'])) { echo 'you attacked' . $decodedData; // ATTACK SQL QUERY GOES HERE $_SESSION['LAST_ATTACK'] = time(); // RELOAD THE PAGE AFTER ATTACK // reloadPage(); } elseif (isset($_SESSION['LAST_ATTACK']) && (time() - $_SESSION['LAST_ATTACK'] > 1)) { echo 'you attacked' . $decodedData; $_SESSION['LAST_ATTACK'] = time(); // ATTACK SQL QUERY GOES HERE // RELOAD THE PAGE AFTER ATTACK // reloadPage(); } else { // DISPLAY ERROR MESSAGE echo 'too soon to attack'; echo '<br />'; // SET SESSION echo $_SESSION['LAST_ATTACK']; echo '<br />'; // RELOAD THE PAGE AFTER ATTACK // reloadPage(); } } } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/297028-adding-an-else-to-a-nested-if-statement/ Share on other sites More sharing options...
Solution ginerjm Posted June 25, 2015 Solution Share Posted June 25, 2015 if (condition) { if (condition) { statements... } else { statements... } } else { statements... } Quote Link to comment https://forums.phpfreaks.com/topic/297028-adding-an-else-to-a-nested-if-statement/#findComment-1514943 Share on other sites More sharing options...
cloudll Posted June 25, 2015 Author Share Posted June 25, 2015 Got it, cheers. Quote Link to comment https://forums.phpfreaks.com/topic/297028-adding-an-else-to-a-nested-if-statement/#findComment-1514944 Share on other sites More sharing options...
ginerjm Posted June 25, 2015 Share Posted June 25, 2015 HTH! BTW - the example was supposed to be indented for ease of understanding and readability. The forum didn't seem to respect my spacing. I like to keep the braces at the same indent level as the verb they belong to, with the statements inside the braces indented one stop. And so on. Quote Link to comment https://forums.phpfreaks.com/topic/297028-adding-an-else-to-a-nested-if-statement/#findComment-1514945 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.