Button clicks and sessions

Hey everyone, something really weird has been bugging me. Tried to find the problem i just can’t think of anything that could be wrong with it…

here is the code maybe someone on here might be able to help.

[php]if(isset($_POST[‘battles’]))
{
$_SESSION[‘npcid’] = $npcid;
}

	echo"<form method='post' action='fight.php'>
		<input type='submit' name='battles' value='fight' >
		</form>";[/php]

So if i remove the if(isset($_POST[‘battles’])) which activates when the button is clicked the session works fine but when i add it nothing works, I tried many different ways that could help me for example replacing it with if($_SERVER[‘REQUEST_METHOD’] == “POST”) but no luck, nothing.

I did add session start because like I said it doesn’t work only when i add that button click…

If anyone has any ideas to what’s wrong with this small code please help me because i really am lost.

Thank you.

An easy way to debug input being sent by a user is to run:

[php]print_r($_POST);[/php]
Or
[php]print_r($_GET);[/php]

Also, make sure you have:

[php]session_start();[/php]

Before any content is outputted to the user (right at the top of your code) - this function call is required on any page(s) that will be using your sessions.

I’ve not confirmed this myself, but apparently some versions of IE do not send the submit button, you could always use a hidden input instead :slight_smile:

[php][/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service