Skip to content Skip to sidebar Skip to footer

How To Update Data Using Onclick Even Checkbox Without Button Submit In Php And Mysql

How, can i update status when i click the check box?..this's my code... i already find and try hard but realy i cant finding anything, please to take out me from this problem,, thi

Solution 1:

You can try by this way

<pid="costumersdata">Print Sucess or Fail</p><inputclass="button blue small"name="btnBaca"type="checkbox"value="R"onClick="gotoupdate(this.value)"><inputclass="button red small"name="btnKirim"type="checkbox"value="D"onClick="gotoupdate(this.value)"/><inputclass="button orange small"name="btnPending"type="checkbox"value="P"onClick="gotoupdate(this.value)"/><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><script>functiongotoupdate(btnBaca){
    $.post("ajax.php?btnBaca="+btnBaca, 
        function(data){
            $("#costumersdata").html(data);
    }); 
}
</script>

On your ajax.php page

<?phpif(isset($_POST["btnBaca"])) {

    // Query Update status$Kode       = $_POST["btnBaca"];

    if($Kode == 'R'){
        $mySql1 = "UPDATE pemesanan set status='DiBaca'  WHERE kd_pesan='$Kode'";
    }elseif($Kode == 'D'){
        $mySql1 = "UPDATE pemesanan set status='DiKirim' WHERE kd_pesan='$Kode'";
    }else{
        $mySql1 = "UPDATE pemesanan set status='Pending' WHERE kd_pesan='$Kode'";
    }

    $myQry1 = mysql_query($mySql1, $koneksidb) ordie ("Gagal query".mysql_error());

    if($myQry1){

        echo"<meta http-equiv='refresh' content='0; url=?page=Pemesanan-Data'>";
    }
  exit;
}
?>

Post a Comment for "How To Update Data Using Onclick Even Checkbox Without Button Submit In Php And Mysql"