IF statement & Button

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
jsk1gcc
Forum Newbie
Posts: 17
Joined: Fri Dec 31, 2010 4:02 pm

IF statement & Button

Post 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. =)
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: IF statement & Button

Post by cpetercarter »

How about using 'elseif' instead of 'if'? Then your if statement will be called only if there is submitted form data.
jsk1gcc
Forum Newbie
Posts: 17
Joined: Fri Dec 31, 2010 4:02 pm

Re: IF statement & Button

Post 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>";
}
=)
Post Reply