dimanche 15 mai 2016

Only 1 checkbox can be checked? PHP

I'm having an issue with checkboxes. I can check both checkboxes, but after submitting, only 1 checkbox is checked. I want them to both be checked after submitting.

Why are they not both checked after submit? What's going wrong in the process?

<?php
$id = $_GET["id"];
$stmt = $dbConnection->prepare('SELECT * FROM paginas WHERE id = ?');
$stmt->bind_param('s', $id);
$stmt->execute();
$result = $stmt->get_result();
if(mysqli_num_rows($result) > 0) {
    while ($row = $result->fetch_assoc()) {
        ?>
        <a href="javascript:;" data-toggle="modal" data-target="#terugnaarpaginas" class="h1url">Terugkeren naar mijn pagina's</a>
        <h1>Wijzig pagina: <?php echo $row["name"]; ?></h1>
        <?php
        if(isset($_POST["opslaan"])) {
            if(empty($_POST["heading"])) {
                echo '<p class="error">Titel kan niet leeg zijn</p>';
            } elseif(empty($_POST["content"])) {
                echo '<p class="error">Content kan niet leeg zijn</p>';
            } else {
                $heading = $_POST["heading"];
                $content = $_POST["content"];
                $updated = date("d-m-Y H:i:s");
                $id = $row["id"];
                $public = $_POST["public"];
                $menu = $_POST["menu"];
                $stmt = $dbConnection->prepare('UPDATE paginas SET heading = ?, content = ?, updated = ?, public = ?, menu = ? WHERE id = ?');
                $stmt->bind_param('ssssss', $heading, $content, $updated, $public, $menu, $id);
                $stmt->execute();

                echo '<p class="success">Wijzigingen zijn succesvol opgeslagen. <a href="">Bekijken</a></p>';
            }
        } else {
?>
<form method="POST" action="">
    <input type="text" name="heading" id="fulltext" placeholder="Titel" value="<?php echo $row["heading"]; ?>">
    <textarea id="fullbox" class="editor" name="content"><?php echo $row["content"]; ?></textarea>
    <div class="pad"><input type="checkbox" name="public" id="public" value="<?php
    if($row["public"] == "1") {
        echo '0';
    } else {
        echo '1';
    }
    ?>" <?php
    if($row["public"] == "1") {
        echo ' checked';
    } else {
        echo '';
    }
    ?>><label for="public" class="checker">Gepubliceerd</label><input type="checkbox" name="menu" id="menu" value="<?php
    if($row["menu"] == "1") {
        echo '0';
    } else {
        echo '1';
    }
    ?>" <?php
    if($row["menu"] == "1") {
        echo ' checked';
    } else {
        echo '';
    }
    ?>><label for="menu" class="checker">Menu</label></div>
    <div class="clear"></div>
    <p id="left">Laatst gewijzigd: <?php echo $row["updated"]; ?></p><input type="submit" value="Bewaar wijzigingen" name="opslaan" class="nomp">
    <div class="clear"></div>
</form>
<?php
        }
    }
} else {
    echo '<p>Deze pagina bestaat niet.</p>';
}
?>




Aucun commentaire:

Enregistrer un commentaire