Php 保存在下拉列表的数据库值中
我正在做一个下拉列表,我想当用户选择一个值时,保存到数据库 这是我的代码:Php 保存在下拉列表的数据库值中,php,html,mysql,Php,Html,Mysql,我正在做一个下拉列表,我想当用户选择一个值时,保存到数据库 这是我的代码: $query = mysql_query("SELECT name FROM store_locator_bundes"); echo '<select name="bundesland-dropdown">'; while ($row = mysql_fetch_array($query)) { echo '<option value="'.$row['name'].'">'.$row[
$query = mysql_query("SELECT name FROM store_locator_bundes");
echo '<select name="bundesland-dropdown">';
while ($row = mysql_fetch_array($query)) {
echo '<option value="'.$row['name'].'">'.$row['name'].'</option>';
}
echo '</select>';
谢谢你的帮助;) 你想要什么
$_POST['bundesland-dropdown']; // You want the <select> not the <options>'s name
$variable=$\u POST['bundesland-dropdown']
然后将$sql=“插入到存储定位器(bundes\u id)值(“$variable.”)中”;像这样,你想在数据库中插入什么?只是名字?每个商店都有id吗?München München2类似于此值,但我只想在bundes_id字段中插入1个值,但我必须将bundes_id重命名为bundes_名称插入商店定位器_bundes(bundes_名称)值(“$variable”),其中bundes_名称=$variable
$_POST['bundesland-dropdown']; // You want the <select> not the <options>'s name
if (isset($_POST['bundesland-dropdown'])){
//mysqli/PDO/whatever database method of insertion you want here
}