2

I have used this to collect the checkbox value array.

    <form action="example.php" method="post" name="deleteform">
    <input type="submit" value="delete"/>

    <table>
    <?php

    foreach ($memArray as $row) {
       echo "<tr align=\"center\">
       <td><input type=\"checkbox\" value=\"".$row['cus_id']."\" name=\"del[]\" /></td>";   
         echo "</tr>";  
    }
    ?>
    </table>
</form

>

if the form is Posted, then do

    $delArray = $_POST['del'];

    print_r($delArray);

But the result returned Array, but nothing inside

I have changed name=del instead of name=del[], and it works . But when i add the [] back it return empty array

8
  • 2
    Checkboxes which are not checked do not get submitted with the rest of the form. Commented Feb 23, 2012 at 5:23
  • check form method.. is that post or you have set it to get..? Commented Feb 23, 2012 at 5:23
  • It's inside a form, i m using post method. Commented Feb 23, 2012 at 5:24
  • try print_ring the entire $_POST variable. See what you can find there. Commented Feb 23, 2012 at 5:28
  • it returned Array ( [del] => Array [deleteinfo] => true ) Commented Feb 23, 2012 at 5:41

2 Answers 2

2

you should check 2 things.

first is form method. whether it is post or get..

second when you submit the page, check box is checked or not. if it is not checked then you can not have array in $_GET or in $_POST

Sign up to request clarification or add additional context in comments.

3 Comments

Both checked. I m using post and the check box is checked
Thanks. But still not working, I have changed name=del instead of name=del[], and it works . But when i add the [] back it return empty array
this is something strange but happy that you got the solution.. :)
2

Here is your code, though i have made changes to loop. checkbox.php is the current file name.

    <?php
    if(isset($_POST['delete']))
    {
        print_r($_POST['del']);
    }
?>
<form action="checkbox.php" method="post" name="deleteform">
<input type="submit" value="delete" name="delete"/>

<table>
<?php

for($i=0;$i<5;$i++) {
   echo "<tr align=\"center\">
   <td><input type=\"checkbox\" value=\"".$i."\" name=\"del[]\" /></td>";
     echo "</tr>";  
}
?>
</table>

Compare it with your code. On submit you'll get definitely get array.

2 Comments

Thanks. But still not working, I have changed name=del instead of name=del[], and it works . But when i add the [] back it return empty array
My advice please go thru your whole codding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.