Jump to content

Dropdown box help


01hanstu

Recommended Posts

Hi,

Sorry. This is the existing code:

 

 <? 
		$getroomsquery = "SELECT * from rooms";
		$getroomresults = mysql_query($getroomsquery);
		$getroomcount = mysql_num_rows($getroomresults);
		$loop = 0;
	?>	
        <form name="roomform" method="post" action="bookingindex.php?week=<? print $mondaythisinstance ?>">
          <select name="selectroom" class="formnames">
	               <option value=" <?PHP print $room ?>" selected>Selected: <?PHP print $room ?></option>
	 <option value="">- - - - - - - - - - -</option>
  <? while ($loop < $getroomcount) 
            {
		print"<option value=\"".mysql_result($getroomresults,$loop,"roomname")."\">".mysql_result($getroomresults,$loop,"roomname")."</option>";
            $loop ++;
		}
		?>
          </select>
          <input name="Submit" type="submit" class="formnames" value="Go">
          </div>
      </form><

The issue is that when it populated the dropdown box, i added the part to show the 'Selected:Room1' room, but some people are just clicking submit, and it tries to show the room 'Selected:Room1', which doesn't exist, whereas room1 does.

 

Please Advise,

- Stuart

 

Link to comment
https://forums.phpfreaks.com/topic/217735-dropdown-box-help/#findComment-1130338
Share on other sites

The best way to do it would be to check if the form field is set, and its value is in the array of values that were used to build the list of <options>, but absent that list, this is the best I can do for the moment . . .

 

if( isset($_POST['selectroom']) && $_POST['selectroom'] != "" ) {
     // a value is set, so do something.
} else {
     // no value is set, so kick out an error.
}

Link to comment
https://forums.phpfreaks.com/topic/217735-dropdown-box-help/#findComment-1130341
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.