Button clicks and sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
musbah
Forum Newbie
Posts: 11
Joined: Mon Apr 25, 2011 8:52 pm

Button clicks and sessions

Post 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.
TheTrueBurger
Forum Newbie
Posts: 1
Joined: Sun Jul 24, 2011 10:13 pm

Re: Button clicks and sessions

Post 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.
musbah
Forum Newbie
Posts: 11
Joined: Mon Apr 25, 2011 8:52 pm

Re: Button clicks and sessions

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Button clicks and sessions

Post 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
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply