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
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
Share on other sites

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.