Jump to content

adding an }else{ to a nested if statement


cloudll

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.