php - 保存在下拉列表的数据库值中

标签 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['name'].'</option>';
}
echo '</select>';

还有条件

if($_POST[$criteria['submit']['name']]) {
    // here I am lost, I have to insert the values of the dropdown to store_locator and the field bundes_id
}

感谢您的帮助;)

最佳答案

你想要

$_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
}

关于php - 保存在下拉列表的数据库值中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21461159/

相关文章:

php - Laravel,仅按日期过滤时间戳

html - 导航栏 HTML CSS 中的下拉菜单中没有任何内容

PHP 面包屑循环

html - 表格宽度和样式宽度的区别

python下载数据(urllib、urllib2)

MySQL 选择连接空值

php - 使用 codeigniter 事件记录集从 mysql 获取数据时 CodeIgniter 中的 UTF-8 问题

PHP pg_connect 连接字符串

PHP MySQL : update table with value of an array combine

javascript - 删除评论而不刷新页面