Jump to content

Help - Submitting Drop Down Value to DB -


fulcrum2

Recommended Posts

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

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.

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.