torvald_helmer Posted May 4, 2007 Share Posted May 4, 2007 how to send selected value from drop down list to database Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 4, 2007 Share Posted May 4, 2007 This code is assuming you are on the page that your form action points to. <?php //This gets the value they selected $value = $_POST['value']; //Now insert it into the database mysql_query("INSERT INTO tbl (value) VALUES ('$value')"); ?> In the $_POST['value'] you need to replace "value" with the name of your drop down. Quote Link to comment Share on other sites More sharing options...
mpharo Posted May 4, 2007 Share Posted May 4, 2007 echo "<form name=\"submit_select\" method=\"post\" action=\"page.php\"><select name="\select"\ onChange=\"document.submit_select.submit();\"><option value=\"option1\">Option 1</option><option value=\"option2\">Option 2</option></select></form>"; page.php $insert=mysql_query("INSERT INTO table (field) VALUES ('$_POST[select]')") or die(mysql_error()); If ($insert) { echo "insert sucessful!"; }Else{ echo "insert failed!"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.