Jump to content

Recommended Posts

Reworded question:

 

 

I am trying to make this code subtract a value from a session, echo it, and keep doing that until it reaches 0. I am using a form that says "Do you want to attack? or Flee?" when they click attack, ideally I would like the form to disappear, the values to be updated, and then echoed again. If they click flee I want it to use a header() to send them back to the main page.

 

My problem is, that after clicking "Attack" the page doesn't execute code it just reloads itself. here is the code that I believe to be the suspect of the matter:

<?php
				if(!$_POST['confirm']){
					echo "<form action='fcenter.php?page=planet1' method='post'>
					<input type='radio' name='attack' value='Attack'/>Attack<br/>
					<input type='radio' name='attack' value='Flee'/> Flee <br/> 
					<input type='submit' name='confirm' value='Choose'/>
					</form> "; 
				}

				if(isset($_POST['confirm'])){ 

					if($_POST['attack']=="Attack"){ 
                                                         $i = $row['attack'];	
						if(intval($i) > 20){
                                                                $dam = $row['attack']-$_SESSION['defenseDrone'];
                                                                $_SESSION['healthDrone']=$_SESSION['healthDrone']-$dam; 

							echo "Testing HellO! ".$_SESSION['healthDrone'];
						}

						if(intval($i) < 20){ 
							echo "Hi"; 
						}

					} 

					else if($_POST['attack']=="Flee"){ 
						echo "Hi";  
					}

				}
?>

 

I'm not sure if the form is wrong or something, but it still, nonetheless, refuses to cooperate.

that code works ok for me.

 

you are selecting a radio button before submitting the form right? Maybe you should add a default selection.

 

just add this to the default radio button

 

selected="selected"

 

Also add error_reporting(E_ALL) see if you get any errors...

It probably works okay because you weren't logged in like a member of the site would be  :P .

 

Anyway, yeah I want them to select an option for the <select> form and then after some code is executed, I want them to select a radio button. However, after the user gets to the radio thing and selects (and presses "Confirm") the page doesn't move onto other code, it just reloads itself.

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.