dqb77047 2011-10-19 09:50
浏览 83
已采纳

从复选框中获取ID

I'm trying to get the ID's from a load of checkboxes that are in rows that are printed out on a page using a while statement. Each row from the database has a checkbox next to it with the ID in the checkbox value.

Basically I want to do a update query on the checkbox-selected rows, using the ID.

The code for the checkboxes that I have used is:

<input type="checkbox" name="check_list[]" value="<? echo $rows['id']; ?>">

Then when the code for the submit is:

<?
if(!empty($_POST['check_list'])){
     foreach($_POST['check_list'] as $id){
        echo "$id was checked! ";
     }
   }
?>

Just wanted to echo out the results to test that it works before putting it into a query. Trouble is...nothing happens. I just get a blank screen. No error or anything. Surely it should work, it looks right but I don't understand why it doesnt work.

Any help is most appreciated! :)

  • 写回答

1条回答 默认 最新

  • dongpan5289 2011-10-21 10:25
    关注

    Tested below code with one test.php file

    <?php
    if(!empty($_POST['check_list']))
    {
         foreach($_POST['check_list'] as $id){
            echo "<br>$id was checked! ";
         }
    }
    
    
    ?>
    
    <form method="post" name="frm">
    <input type="checkbox" name="check_list[]" value="1"> 1
    <input type="checkbox" name="check_list[]" value="2"> 2
    <input type="checkbox" name="check_list[]" value="3"> 3
    <input type="checkbox" name="check_list[]" value="4"> 4
    <input type="submit" name="submit" />
    </form>
    

    please check if you are getting $rows['id'] properly. Things should work fine otherwise.

    Thanks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?