Page 1 of 1

Button clicks and sessions

Posted: Mon Jan 02, 2012 5:01 pm
by musbah
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.

Code: Select all

if(isset($_POST['battles']))
			{
				$_SESSION['npcid'] = $npcid;
			}
		
		echo"<form method='post' action='fight.php'>
			<input type='submit' name='battles' value='fight' >
			</form>";
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.

Re: Button clicks and sessions

Posted: Mon Jan 02, 2012 6:21 pm
by TheTrueBurger
Could you post the whole file or is it too large? I am not seeing anything wierd, but I am a noob too.

Re: Button clicks and sessions

Posted: Mon Jan 02, 2012 6:47 pm
by musbah
The whole thing is too large, it shouldn't have to do with the whole thing though, the problem should be somewhere here...

hmm... can t think of anything.

Re: Button clicks and sessions

Posted: Wed Jan 04, 2012 3:11 am
by social_experiment

Code: Select all

<?php $_SESSION['npcid'] = $npcid; ?>
Where is the value of $_SESSION['npcid'] defined?
If you call the page on itself, use action="" instead of a filename