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 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的