dstobkpm908182 2014-05-02 16:28
浏览 77
已采纳

在php中获取未发布输入的值

very common to us to get the value of the post input type with data. but now i want to get if the checbox is check or unchecked. here is my code:

while (!$listof_artist->EOF) {
    $id = $listof_artist->fields['id'];
    $arr_id[] = $id;

    echo "<tr><td><input type='checkbox' value='".$id."' name='chkid[]' id='chkid[]' /></td>";
}

if(isset($_POST['submit'])){
    foreach($_POST['chkid'] as $checkbox){
        //code for add
    }

here is my algorithm: if submit is post then

for each checbox is check
    //add

foreach checbox not check
        //code for not check

Please help. thank you

  • 写回答

4条回答 默认 最新

  • drmticpet66231422 2014-05-02 17:01
    关注

    Similar to what the other answers have already pointed out, here is a way to do it:

    while (!$listof_artist->EOF) {
        $id = $listof_artist->fields['id'];
        $arr_id[] = $id;
    
        echo "<tr><td><input type='checkbox' value='$id' name='$id' id='$id' /></td>";
    }
    
    if(isset($_POST['submit'])){
        foreach($arr_id as $checkbox){
            if (isset($_POST[$checkbox])) {
                // Checkbox is checked
                echo 'Artist id ' . $checkbox . ' is checked <br/>';
            }
            else {
                // Checkbox is NOT checked
                echo 'Artist id ' . $checkbox . ' is NOT checked <br/>';
            }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

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