html - PHP Update The Value if the checkbox is checked with a submit button
one text
I'm having an issue with updating my table when the checkbox is checked, what i'm trying to do is when i check the checkbox and click submit button it will change the value of "Encaiss?�" to green (means yes) this is my table
and this is my code
<?php
$sql = "SELECT * FROM carburant WHERE id_user =" . $_SESSION['id_user'] . "";
$statement = $conn->query($sql);
$res = $statement->fetchALL(PDO::FETCH_ASSOC);
foreach ($res as $roww) {
echo ' <tr>
<td>' . $roww['date'] . '</td>
<td>' . number_format($roww['km']) . '</td>
<td>' . $roww['type'] . '</td>
<td>' . number_format((float)$roww['montant'], 2, '.', ',') . '</td>';
if ($roww['encaisse'] == true) {
echo '<td><span class="badge bg-success">Oui</span></td>';
} else {
echo '<td><span class="badge bg-danger">Non</span></td>';
}
echo '<td> <input type="checkbox" name="encaisse" class="form-check-input" value="' . $roww['id'] . '"/></td> </tr>';
}
if (isset($_POST['sub']) && isset($_POST['encaisse'])) {
$sqlm = "UPDATE carburant SET encaisse = '1' WHERE id='" . $_POST['id'] . "'";
$stmtm = $pdo->prepare($sqlm);
$stmtm->execute($encaisse);
}
?>
and here where i have a problem, so when i execute the code it gives me this error "Not Found The requested URL was not found on this server.", i'm trying to update "ecaisse" by giving it the value of 1 for "yes in green" it's 0 by default which gives it the value "no in red".
if (isset($_POST['sub']) && isset($_POST['encaisse'])) {
$sqlm = "UPDATE carburant SET encaisse = '1' WHERE id='" . $_POST['id'] . "'";
$stmtm = $pdo->prepare($sqlm);
$stmtm->execute($encaisse);
}
Source