-1
我在我的数据库中有行,它有一个名为value
的列。我正在创建一个页面来将值更新为aan(英文:on)或uit(英文:off)。PHP Select submit not working
但是,提交时,值列中有1
而不是aan
或uit
。
行的ID是1,所以这就是为什么有1但我不知道什么是错的,为什么它不提交aan
或uit
。
怎么回事?
<?php
$stmt = $dbConnection->prepare('SELECT * FROM settings ORDER BY id ASC');
$stmt->execute();
$result = $stmt->get_result();
if(mysqli_num_rows($result) > 0) {
?>
<form method="POST" action="">
<table>
<tr>
<th>Naam</th>
<th>Laatst gewijzigd</th>
<th>Waarde</th>
</tr>
<?php
while ($row = $result->fetch_assoc()) {
if(isset($_POST["opslaan"])) {
$id = $row["id"];
$stmt = $dbConnection->prepare('UPDATE settings SET value = ? WHERE id = ?');
$stmt->bind_param('ss', $id, $id);
$stmt->execute();
}
?>
<tr>
<td><?php echo $row["code"]; ?></td>
<td><?php echo $row["updated"]; ?></td>
<td><select name="<?php echo $row["id"]; ?>"><option value="aan"<?php if($row["value"] == "aan") {echo ' selected';} ?>>Aan</option><option value="uit"<?php if($row["value"] == "uit") {echo ' selected';} ?>>Uit</option></select></td>
</tr>
<?php } ?>
</table>
<input type="submit" value="Opslaan" name="opslaan">
</form>
<?php
} else {
echo "<p>Er zijn nog geen instellingen.</p>";
}
}
?>
Ca你解释多一点?我已经尝试了您的建议,但似乎没有奏效。 –
问题是您的选择名称是数字。在这种情况下:1.因此,我的建议是将名称更改为可以逻辑访问的字符串。你可以添加一个var转储到PHP来查看你回来的东西。我会更新代码并现在添加它... – Poiz
你现在可以试试看....我刚才看到你没有真正更新**值**正确的数据在你的数据库列。你是***明确地将其设置为1的rowID。这就是为什么。所以我现在添加了另一个变量$ aanUit,用于更新数据库中的**值**列。现在应该没问题。只要将您的** if(isset($ _ POST [“opslaan”])){**块更改为所提供的***并确保您选择的名称是“aan_uit”*** – Poiz