truck7758 Posted March 27, 2008 Share Posted March 27, 2008 i have created a dropdown menu using the following code <? $mysqli = new mysqli('host','username','password'); $mysqli->select_db('orders'); $result = $mysqli->query("SELECT * FROM quotes"); echo "<SELECT name='quoteid'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['quoteid']}'>{$row['quoteid']}</option>\n"; } echo "</select>\n"; $result->close(); ?> this works fine but what i need now is for the default value to be either blank or say something like please select and if nothing else is selected than for it to insert a blank value Thanks, Mike Link to comment https://forums.phpfreaks.com/topic/98135-default-value-for-drop-down-menu/ Share on other sites More sharing options...
ansarka Posted March 27, 2008 Share Posted March 27, 2008 :) <? $mysqli = new mysqli('host','username','password'); $mysqli->select_db('orders'); $result = $mysqli->query("SELECT * FROM quotes"); echo "<SELECT name='quoteid'>\n"; echo "<option value=''>Select</option>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['quoteid']}'>{$row['quoteid']}</option>\n"; } echo "</select>\n"; $result->close(); ?> Link to comment https://forums.phpfreaks.com/topic/98135-default-value-for-drop-down-menu/#findComment-502015 Share on other sites More sharing options...
truck7758 Posted March 27, 2008 Author Share Posted March 27, 2008 This no displays 'Select' as the default value although i have changed this to '0' which is great but now when i submit my form it submits the value '3' ??? Any ideas? Thanks, Mike Link to comment https://forums.phpfreaks.com/topic/98135-default-value-for-drop-down-menu/#findComment-502019 Share on other sites More sharing options...
truck7758 Posted March 27, 2008 Author Share Posted March 27, 2008 i have just done another test and this timme it submitted '2' ??? Thanks, Mike Link to comment https://forums.phpfreaks.com/topic/98135-default-value-for-drop-down-menu/#findComment-502021 Share on other sites More sharing options...
truck7758 Posted March 27, 2008 Author Share Posted March 27, 2008 i have now done a few more tests and it is now just submitting the value '1' and i cannot see where it is getting this value from. Any ideas, Mike Link to comment https://forums.phpfreaks.com/topic/98135-default-value-for-drop-down-menu/#findComment-502034 Share on other sites More sharing options...
truck7758 Posted March 27, 2008 Author Share Posted March 27, 2008 Any ideas??? Thanks, Mike Link to comment https://forums.phpfreaks.com/topic/98135-default-value-for-drop-down-menu/#findComment-502068 Share on other sites More sharing options...
truck7758 Posted March 27, 2008 Author Share Posted March 27, 2008 resolved using previous suggestion by ansarka. the reason it didnt work straight away was i had an error on my insert script Thanks All Link to comment https://forums.phpfreaks.com/topic/98135-default-value-for-drop-down-menu/#findComment-502299 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.