如何将值和内容插入到数据库单独的单独列中。它是一个下拉菜单。喜欢
<select name="name" id="name">
<option value="000">Please select</option>
<option value="calendar.gif">Animal Welfare</option>
<option value="calendar1.gif">Art and Cultural</option>
<option value="calendar2.gif">Career Related</option>
</select>
对于“动物福利”实例,希望将“calendar.gif”插入到一列,将“动物福利”插入到另一列。
最佳答案
将选项 => 值组合存储在数组中。然后您可以使用该数组进行插入和显示,例如
$options = array (
'calendar.gif' => 'Animal Welfare',
'calendar1.gif' => 'Art and Cultural',
'calendar2.gif' => 'Career Related'
);
if (isset($_POST['name']) && array_key_exists($_POST['name'], $options)) {
// valid option submitted
$key = $_POST['name'];
$value = $options[$key];
// now you can insert $key and $value
}
// to display
?>
<select name="name" id="name">
<option value="">Please select</option>
<?php foreach ($options as $key => $value) : ?>
<option value="<?php echo htmlspecialchars($key) ?>">
<?php echo htmlspecialchars($value) ?>
</option>
<?php endforeach ?>
</select>
关于php - 如何将值和内容同时插入数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7006687/