如果复选框被选中,则更新calibrated=';是';并且如果复选框未被选中,则更新calibrated=


if Checkbox is checked then update calibrated = 'yes' and if Checkbox is not checked then update calibrated = 'no'

嗨,你能帮我吗?我现在有check box name='calibrate',,如果勾选了复选框,我想要这个,然后更新校准="是",如果没有勾选复选框,那么更新calibrated = 'no'.

因为这里的问题是,即使我有'Update machine_and_equipments set calibtrated = '$yah' where id = '$id',它也无法在数据库中更新。

<?php
$res = mysql_query("select * from machine_and_equipments where id = '$id'");
$row = mysql_fetch_array($res);
$cal = $row['21']; 
            $d1 = $row['6'];
    if($cal == "yes"){
        $checkthis = "<td >Need to Calibrate?: <input type='checkbox' name='calibrate'  onclick='OnChangeCheckbox(this), enable_text(this.checked)' id='myCheckbox' checked/><label  id='val'><?php echo $yah; ?></label> ";            
    }
    if($cal == "no"){
        $checkthis = "<td >Need to Calibrate?: <input type='checkbox' name='calibrate' onclick='OnChangeCheckbox(this), enable_text(this.checked)' id='myCheckbox' /> ";
    }
    if((isset($_POST['calibrate']))== "yes"){
    $yah = "yes";
    $id      = $_POST['id'];
    $sql = "update machine_and_equipments set calibtrated = '$yah' where id = '$id'";
    $res = mysql_query($sql) or die("could not be update". mysq_error());
    }
    if((isset($_POST['calibrate']))== "no"){
    $yah = "no";
    $id      = $_POST['id'];
    $sql = "update machine_and_equipments set calibtrated = '$yah' where id = '$id'";
    $res = mysql_query($sql) or die("could not be update". mysq_error());
    }
?>

提前谢谢。

试试这个代码。我无法对此发表评论,所以我在回答中写下这篇文章。如果不起作用,请告诉我。

if(isset($_POST['id'])) {
   if((isset($_POST['calibrate']))){
     $yah = "yes";     
   } else {
    $yah = "no";    
   }
   $id      = $_POST['id'];
   $sql = "update machine_and_equipments set calibtrated = '$yah' where id = '$id'";
   $res = mysql_query($sql) or die("could not be update". mysq_error());
}
相关文章: