fulcrum2 Posted April 6, 2007 Share Posted April 6, 2007 Hi - I am trying to create a form with a couple of drop downs and open fields that would be filled out and submitted by a user. I am having trouble figuring out how to tie the selected drop down value to the "Submit" command, so that it gets to the db. Here is my select code, but how do I submit to the db the value that the user selects out of the drop down? Thanks very much for your help!!!! //DROP DOWN CODE __________________________________________ $sqlOptions = "SELECT house_name, house_address1 from house"; $resultOptions = mysql_query($sqlOptions); echo '<select name="selectName">'; echo '<option value="">--Select--</option>'; while($opt = mysql_fetch_array($resultOptions)) { echo '<option value="'.$opt['house_id'].'">'.$opt['house_address1'].'</option>'; } Link to comment https://forums.phpfreaks.com/topic/45903-help-submitting-drop-down-value-to-db/ Share on other sites More sharing options...
Zaid Posted April 6, 2007 Share Posted April 6, 2007 your loop is wrong, and i dont think it is looping at all Link to comment https://forums.phpfreaks.com/topic/45903-help-submitting-drop-down-value-to-db/#findComment-222987 Share on other sites More sharing options...
fulcrum2 Posted April 6, 2007 Author Share Posted April 6, 2007 The drop down displays the data just fine. The problem is how do I post the selected value into the DB? Link to comment https://forums.phpfreaks.com/topic/45903-help-submitting-drop-down-value-to-db/#findComment-222993 Share on other sites More sharing options...
pocobueno1388 Posted April 6, 2007 Share Posted April 6, 2007 Zaid - Her loop looks fine to me 0_o This is how you get the selected value from the drop down box and put it in the database: -Wherever your from action goes to you need to access the value like this- <?php if ($_POST['submit']){ //Put the value of the drop down box into a variable $selectName = $_POST['selectName']; //now insert the value into the DB mysql_query("INSERT INTO tbl_name (col1, col2, col3) VALUES ('$selectName', '$var1', '$var2')"); } ?> It is as easy as that...of course you will have to change the code up to match your DB and all. Link to comment https://forums.phpfreaks.com/topic/45903-help-submitting-drop-down-value-to-db/#findComment-223003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.