Jump to content

value from drop down list to database


Recommended Posts

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.


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!";

}

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.