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

<p id="costumersdata">Print Sucess or Fail</p>

<input class="button blue small" name="btnBaca" type="checkbox" value="R" onClick="gotoupdate(this.value)">
<input class="button red small" name="btnKirim" type="checkbox" value="D" onClick="gotoupdate(this.value)"/>
<input class="button orange small" name="btnPending" type="checkbox" value="P" onClick="gotoupdate(this.value)"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
function gotoupdate(btnBaca){
    $.post("ajax.php?btnBaca="+btnBaca, 
        function(data){
            $("#costumersdata").html(data);
    }); 
}
</script>

On your ajax.php page

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

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

    if($Kode == 'R'){
        $mySql1 = "UPDATE pemesanan set status='DiBaca'  WHERE kd_pesan='$Kode'";
    }else if($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) or die ("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"