torvald_helmer Posted May 4, 2007 Share Posted May 4, 2007 how to send selected value from drop down list to database Link to comment https://forums.phpfreaks.com/topic/50060-value-from-drop-down-list-to-database/ 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. Link to comment https://forums.phpfreaks.com/topic/50060-value-from-drop-down-list-to-database/#findComment-245705 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!"; } Link to comment https://forums.phpfreaks.com/topic/50060-value-from-drop-down-list-to-database/#findComment-245710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.