Jump to content

adding an }else{ to a nested if statement


Go to solution Solved by ginerjm,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/297028-adding-an-else-to-a-nested-if-statement/
Share on other sites

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.

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.