I am trying to make a page where someone selects an option on one form, a code is executed depending on the selection, and then a new form appears for another option.

Could it be that my forms are clashing into each other because when I have them both on one page AND them action="" set to the same page, they don't work. If I have them on the same page but they have different actions, it works.

I do not want to redirect my users to another page and then back (because the one with the different action redirects them to its action). Also, when it redirects them I cannot execute code based on whether or not the second form was completed AFTER they were sent away and back.

here:
FORM 1

<form action='fcenter.php?page=planet1' method='post'>
			<select size='4' name='fight'>
			<option value='Aliens'>Aliens</option>
			<option value='Marines'>Marines</option>
			<option value='Native Animals'>Native Species</option> 
			<option value='Totally Random'>Randomize</option>
			</select> 
			<input type='submit' name='choose' value='Search'/> 
			</form>

FORM 2

 <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' id='confirm' value='Choose'/>
						</form>

Ideal situation:

Member answers form 1 --> Form 2 comes up (answers form 2) --> Code is executed based on what they chose on form 2 (this code involves $_SESSIONs)

What it is doing is this:

Member answers form 1 --> Form 2 comes up (with different action) --> Send to enemy.php --> Redirect back to original page --> Now the original page is reloaded so I cannot execute the code based on form 2!!!!

What if form 1 was a $_GET form? >.> <.< then I could redirect them to...the page they chose?

    There is no problem at all having several forms on one page, nor having them submit to the same script. Just remember that only control values from the submitted form are sent to the server.

    <form action="" method="post">
    	<input type="text" name="one"/>
    	<input type="radio" name="submit1" value="something" onclick="javascript:document.forms[0].submit"/>
    </form>
    
    <form action="" method="post">
    	<input type="text" name="one"/>
    	<input type="text" name="two"/>
    	<input type="submit" name="submit2" value="whatever"/>
    </form>
    
    // handle form 1
    if (isset($_POST['submit1']) {
    	// Input from the first form
    	$_POST['one']
    }
    // handle form 2
    else if (isset($_POST['submit2']) {
    	// Input from the second form
    	$_POST['one']
    }

    And you can always redirect someone to a page of your choice, using a suitable status code.

    // Most likely one of...
    header("HTTP/1.1 301 Moved Permanentely");
    header("HTTP/1.1 302 Found");
    header("HTTP/1.1 303 See Other");
    
    // Followed by
    header("Location: http://someplace.else.com/somescript")

      Okay. How come when I do use two forms and have different sections for each form, they still just reload the page? If I make the script for the second form on another page it does work, but not if it's on the same page as the first. Here's my whole code:

      <?php
      include "db.php"; 
      $result=mysql_query("SELECT * FROM rpg WHERE player='{$_SESSION['username']}'") or die(mysql_error());
      
      while($row=mysql_fetch_array($result)){ 
      
      echo "<strong>".$row['name']."</strong><br/>
      <strong>".$row['species']."</strong><br/>
      <strong> Health: ".$row['health']."</strong><br/>
      <strong> Attack: ".$row['attack']."</strong><br/>
      <strong> Defense: ".$row['defense']."</strong><br/>
      <strong>"; 
      
      	if($row['species']=="Alien"){ 
      		echo "Stealth: ".$row['stealth']; 
      	} 
      
      	if($row['species']=="Marine"){ 
      		echo "Melee: ".$row['melee'];
      	}
      
      echo "</strong>
      <strong>Money: ".$row['money']."</strong>";
      echo "</td><td>";
      
      	if(!$_POST['choose']){
      		echo "Choose an Enemy to Fight 
      		<form action='fcenter.php?page=planet1' method='post'>
      		<select size='4' name='fight'>
      		<option value='Aliens'>Aliens</option>
      		<option value='Marines'>Marines</option>
      		<option value='Native Animals'>Native Species</option> 
      		<option value='Totally Random'>Randomize</option>
      		</select> 
      		<input type='submit' name='choose' value='Search'/> 
      		</form>"; 
      	}
      
      	if($_POST['choose']){ 
      
      		if($_POST['fight']=="Aliens"){ 
      			$randA = mt_rand(1,20);
      
      			if($randA=="1" || $randA=="7" || $randA=="2" || $randA=="20"){ 
      				echo "<script> alert('You have not found an enemy to fight. Please try again.'); 
                                          location='fcenter.php?page=planet1'; </script>"; 
      			} 
      
      			if($randA=="3" || $randA=="6" || $randA=="11" || $randA=="8" || $randA=="16" || $randA=="4" || $randA=="10" || $randA=="19"){ 
                                          $_SESSION['name']="Alien Drone";
                                          $_SESSION['attackDrone']="25"; 
                                          $_SESSION['defenseDrone']="20"; 
                                          $_SESSION['healthDrone']="20"; 
      
                                          function showEnemy(){ 
                                            echo "<strong>Enemy:</strong> ".$_SESSION['name']."<br/> 
      				<strong>Attack:</strong> ".$_SESSION['attackDrone']."<br/>
      				<strong>Defense:</strong> ".$_SESSION['defenseDrone']."<br/>
                                          <strong>Health:</strong> ".$_SESSION['healthDrone']."<br/>
      				<strong>Money for Kill:</strong> 100<br/> 
      				<strong>Experience:</strong> 10<br/>";
      					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' id='confirm' value='Choose'/>
      					</form> "; 
                                          } 
                                          showEnemy(); 
      
      
      				if($_POST['confirm']){
                                          require("enemy.php");
                                          do{
                                          showEnemy(); 
                                          }
                                          while($_SESSION['healthDrone'] > "0");
      				}
      
      
      
      			}
      		}
      	}
          }
      
      
      
      ?>	

        When confirm is set, choose isn't.

        And do use php tags, not code tags.

          Okay, but I've found a work-around solution...

            Write a Reply...