Page 1 of 1

IF statement & Button

Posted: Sun Jan 09, 2011 7:30 pm
by jsk1gcc
I have two drop down boxes which give me $extract and $extract2. The user can not select the same seat from each drop down. I don't know how to get my IF statement to work.
well it does work but because when the page loads both boxes are null and the same the 'else' message appears

is there a way to say.... ignore IF statement if both boxes are null?

Code: Select all

//SUBMIT BUTTON	
echo "<br>";
echo "<br>";
echo "<input type='submit' name='select' value='Select Seats'>";
echo "</form>";	

//IF TO SEE IF TWO SEATS ARE SAME
if ($_POST['select']="")
{
echo "please choose seats";
}
if ($_SESSION['extract']==$_SESSION['extract2'])
{
echo "You have choosen the same seat twice, please choose two different seats.
<a href='confirm.php'> Go Back</a>";
}


Thanks. =)

Re: IF statement & Button

Posted: Mon Jan 10, 2011 1:04 am
by cpetercarter
How about using 'elseif' instead of 'if'? Then your if statement will be called only if there is submitted form data.

Re: IF statement & Button

Posted: Mon Jan 10, 2011 4:36 am
by jsk1gcc
you're awesome. Thankyou =) elseif works a treat.

here is the code for anyone else who has this problem:

Code: Select all

//QUERY ONE
$extract =mysql_query("SELECT * FROM ride WHERE rideID ='3'");
$numrows = mysql_num_rows($extract);

//DROP DOWN BOX ONE
echo '<form method="post" name="f1" action="confirm.php">';
echo 'Please choose a seats:  '; echo"<select multiple name='seat' size='2'>";

		while( $row = mysql_fetch_assoc($extract)) 
		{   
			$rideID = $row ['rideID'];
			$name = $row ['name'];
			$seatNumber = $row ['seatNumber'];
			$time = $row ['time'];
			$price = $row ['price'];
			
			echo "<option name='seat'> $seatNumber </option>";
			$_SESSION['extract']=$_POST['seat'];
		}  
			echo '</select>'; 
			
//QUERY TWO
$extract2 =mysql_query("SELECT * FROM ride WHERE rideID ='3'");
$numrows = mysql_num_rows($extract2);

//DROP DOWN BOX TWO
echo"<select multiple name='seat2' size='2'>"; 
		
		while( $row = mysql_fetch_assoc($extract2)) 
		{   
			$rideID = $row ['rideID'];
			$name = $row ['name'];
			$seatNumber = $row ['seatNumber'];
			$time = $row ['time'];
			$price = $row ['price'];
			
			echo "<option name='seat2'> $seatNumber </option>";
			$_SESSION['extract2']=$_POST['seat2'];
		}  
			echo '</select><br>'; 

//SUBMIT BUTTON	
echo "<br>";
echo "<br>";
echo "<input type='submit' name='select' value='Select Seats'>";
echo "</form>";	

//IF TO SEE IF TWO SESSIONS ARE SAME 
if ($_POST['select']=="")
{
echo "please choose seats";
}
elseif ($_SESSION['extract']==$_SESSION['extract2'])
{
echo "You have choosen the same seat twice, please choose two different seats.
<a href='confirm.php'> Go Back</a>";
}
=)