I have rows in my database and it has a column called value
. I'm making a page to update the value to aan (English: on) or uit (English: off).
However, when submitted, there's a 1
in the value column instead of aan
or uit
.
The ID of the row is 1, so that's why there's a 1 but I don't know what is going wrong and why it's not submitting the aan
or uit
.
What's going wrong?
<?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>";
}
}
?>