dpz90118 2013-12-05 10:22
浏览 27

如果未勾选复选框,则从表中删除

This is probably an easy one but I am stuck. I have a form with checkboxes that show employees and there skills, these are taken from a table with a many to many relationship. The below code works for updating the records but I am unsure on how to delete records if the checkbox is un-checked

$emp=$_POST['emp'];  

if(isset($_POST['chk1'])){
    $checkbox=$_POST['chk1'];
    $arr_num=count($checkbox);
    $i=0;

    while ($i < $arr_num)
    {
        $qry = "INSERT IGNORE INTO skillsets (skill_id, empr_id )VALUES(?, ?)";
        $stmt = $mysqli->prepare($qry);
        $stmt->bind_param('ii', $checkbox[$i], $emp);
        $stmt->execute();
        $i++;
    }
}
 else .... delete from .....

I am not sure of the syntax for the else, can someone help me out?

  • 写回答

1条回答 默认 最新

  • duanfei8149 2013-12-05 10:27
    关注

    You can define hidden inputs for every checkbox (before it) with the same name. Eg.

    <input type="hidden" name="items[1]" value="no" />
    <input type="checkbox" name="items[1]" value="yes" />
    

    1 is your item ID. And now if checkbox is checked then its value will be send. In other case, value from hidden field will be send to your server. With this data you can iterate through items array, get ID from index and check value to know if it's checked or not.

    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)