• 13-11-2022, 16:43:49
    #1
    Merhabalar sweetalert kullanarak silme işlemi yapmak istiyorum ama hata veriyor çözemedim yardım ederseniz sevinirim.
            <button class="btn btn-danger mt-2" onClick="surucusil(<?php echo $lang_id; ?>)">Sil</button>
    <script type="text/javascript">
        function surucusil(id) {
    Swal.fire({
      title: 'Are you sure?',
      text: "You won't be able to revert this!",
      icon: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
      if (result.isConfirmed) {
          window.location.href = 'webting/sil_islem.php?kullanicisil=ok&kullanici_id='+id;
      }
    })
    };    
        
        
        </script>
    <?php
    ob_start();
    session_start();
    
    include 'baglan.php';
    
    
    // SİLME İŞLEMİ //
    
    if($_GET['kullanicisil']=="ok"){
        
        $id        =     ($_GET['kullanici_id']);
        $select    =    $db->prepare("SELECT * FROM data_kullanici WHERE kullanici_id ='$id'");
        $select -> execute(array($id));
        $bul    = $select->fetch(PDO::FETCH_ASSOC);
        $resim    =    $bul["kullanici_resim"];    
        unlink("../$resim");
    
        
        $sil=$db->prepare("DELETE FROM data_kullanici WHERE kullanici_id=:kullanici_id ");
        $kontrol=$sil->execute(array(
            'kullanici_id' => $_GET['kullanici_id']
        ));
    
        if($kontrol){
            header("Location:../surucu_list.php?durum=silindi");
        }else{
            header("Location:../surucu_list.php?durum=silinmedi");
        }
        
        
    }
    
    //----BİTİŞ----//
    hata
    Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in D:xampphtdocsehliyetwebtingsil_islem.php:14 Stack trace: #0 D:xampphtdocsehliyetwebtingsil_islem.php(14): PDOStatement->execute(Array) #1 {main} thrown in D:xampphtdocsehliyetwebtingsil_islem.php on line 14

    şimdiden herkese teşekkürler
  • 13-11-2022, 16:50:55
    #2
    $db->prepare("SELECT * FROM data_kullanici WHERE kullanici_id ='$id'"); şurda hata var.

    Doğrusu
    $db->prepare("SELECT * FROM data_kullanici WHERE kullanici_id =?");
  • 13-11-2022, 22:53:19
    #3
    omergunay adlı üyeden alıntı: mesajı görüntüle
    $db->prepare("SELECT * FROM data_kullanici WHERE kullanici_id ='$id'"); şurda hata var.

    Doğrusu
    $db->prepare("SELECT * FROM data_kullanici WHERE kullanici_id =?");
    Çok teşekkür ederim