v2.5.2
Giriş yap

butona tıklayınca kayıt etme

Anonim
311 defa görüntülendi
<script type="text/javascript">
    $(function () {
        <?php
        $hour_control = $db->query("SELECT * FROM doctor_hours WHERE hourstitle = '{$doctors['id']}' AND days= 'Pazartesi' ", PDO::FETCH_ASSOC);
        if ($hour_control->rowCount()) {
            foreach ($hour_control as $c) {
        ?>
        $('input[name="hour[]"][value="<?php echo $c['hours']; ?>"][id="pzt<?php echo $c['hours']; ?>"]').attr('checked', 'checked');
        <?php }
        } ?>
    });
</script>
<form method="post">
    <div class="user__head">
        <?php
            $query = $db->prepare("SELECT * FROM hours ORDER BY id ");
            $arama = $query->execute();
            foreach ($query as $row) {
            ?>
        <input type="checkbox" name="hour[]" value="<?= $row['id'] ?>" class="checkbox" id="pzt<?= $row['id'] ?>">
        <label class="button-strokebutton" for="pzt<?= $row['id'] ?>" style="margin-bottom: 16px;"><?= $row['hour'] ?></label>
        <?php } ?>
    </div>
    <div class="setting__controls">
        <button class="button setting__button" type="submit" name="pzt">
            Güncelle
        </button>
    </div>
</form>
<?php
if (isset($_POST['pzt'])) {
    $delete = $db->exec("DELETE FROM doctor_hours WHERE hourstitle = '{$_SESSION['kullanici']['id']}' AND days = 'Pazartesi' ");
    if ($_POST['hour']) {
        foreach ($_POST['hour'] as $k) {
            $islem = $db->prepare("INSERT INTO doctor_hours SET hourstitle = ?, hours = ?, days = ?");
            $islem = $islem->execute(array($_SESSION['kullanici']['id'], $k, 'Pazartesi'));

            if ($islem) {
                header('Location:hesabim');
            } else {
                header('Location:hesabim');
            }

        }
    }
}
?>

Çıktı

Saatlere tıklayınca direkt veritabanına kayıt etsin istiyorum ` <button class="button setting__button" type="submit" name="pzt">

        Güncelle
    </button> ``` kısmı olmadan bunu nasıl yapabilirim
Cevap yaz
Cevaplar (1)
devepdogukan
1037 gün önce

Oluşturduğun saatlere tıklanma eventini dinleyerek direkt ajax yaptırtabilirsin.

$(document.body).on("click",'.user__head input[type='checkbox']',function(){
const value = $(this).val();
    <!-- ajax kodun -->
})