php - 如何使用选择选项将 id 提取到数据库
问题描述
确实,我的问题很简单。当我更改“选项”时,我必须拉它的 ID。也许它可以工作javascript。但我不知道javascript。
<h4><u> Upload Image </u></h4>
<form action="a.php" method="post" enctype="multipart/form-data">
<label style="font-size:16px;" for="selectalbum">Select Album</label>
<select style="margin-left:10px;" name="selectalbum">
<?php
$imagequery=$db->prepare("SELECT * FROM imagealbum");
$imagequery->execute(array());
$imgquery=$imagequery->fetchAll(PDO::FETCH_ASSOC);
foreach($imgquery as $imagealbum) {
?>
<option value="<?php echo $imagealbum['imagealbum_id']; ?>"><?php echo $imagealbum['imagealbum_name']; ?></option>
<?php } ?>
</select>
<br>
<input type="text" name="aaa" style="text-align:center;">
<br><br>
<input type="text" style="text-align:center;" value="<?php echo $imagealbum['imagealbum_id']; ?>">
<br><br>
<input type="file" name="files[]" value="Upload Image" />
<br>
<button style="margin-top:7px; width:90px; height:30px; background-color:green; color:#fff; border-radius:7px;" name="submit">Submit</button>
</form>
解决方案
尝试使用 getId 的函数添加 onchange 事件,如下所示:
const getId = () => {
const album = document.querySelector('#albums');
const log = document.querySelector('#log');
log.innerHTML = ` Id: ${album.value}`;
}
window.onload = function() {
getId();
};
<label for="albums">Select Album:</label>
<select name="albums" id="albums" onchange="getId()">
<option value="123">Album 1</option>
<option value="321">Album 2</option>
<option value="159">Album 3</option>
</select>
<div id="log">
</div>
推荐阅读
- java - actionView() 的问题 - java.lang.NullPointerException:
- python - python使用全局变量而不在本地范围内将其定义为全局变量
- bazel - 名称“浮动”未定义:Starklark / Bazel
- css - Framer Motion 不更新 scrollYProgress
- python - Python csv模块获取列数并打印信息
- c++ - 如何将特征矩阵转换为 C/C++ 数组
- r - 对于 mtcars 数据,您如何使用 R 找到具有不同级别(带有 3 个示例场景)的变量的所有可能的唯一成对比较?
- vue.js - vue with parcel 无法正确渲染
- asp.net-mvc - Kendo UI MVC 的密码文本框
- postgresql - Kafka Sink 如何将字段映射到具有不同主题和表模式名称的数据库