Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 保存在下拉列表的数据库值中_Php_Html_Mysql - Fatal编程技术网

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
}