如果选中复选框,则更新校准='是'如果未选中Checkbox,则更新calibrated =' no'

时间:2014-09-06 06:56:34

标签: php mysql

您好我能帮助我check box name='calibrate',现在我想要这个,如果选中Checkbox然后更新校准='是'如果未选中复选框,则更新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());
    }
?>

提前致谢。

1 个答案:

答案 0 :(得分:0)

试试这段代码。我无法评论,所以我写这个回答。如果它不能工作让我知道。

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());
}