Nickool
Nickool

Reputation: 3702

using checkboxes echoing the value of checkbox when checked

I have a,b,c in a table with check boxes I want by clicking sub button echoing value of checkboxes that are checked

<?php
 $array=array('a','b','c');
 echo "<table border=2>";
     for($i=0;$i<3;$i++)
     {
     echo "<tr>
     <td><input type='Checkbox' name='p[$i]'  value='$array[$i]' unchecked />
     <td>$array[$i]</td>
     </tr>";
     }
    echo "</table>";
if(array_key_exists('sub',$_POST))
        if(isset($_POST['p']))
         {
         foreach($_POST['p'] as $key=>$value)
             //I have problem here;
   }
?> 
<html>
<head>
<title></title>
<meta content="">
</head>
<body>
<form method='post'>
<input type='submit' name='sub' value='echome'>
</body>
</html>

I have problem in echoing and if(isset($_POST['p'])) is not working what I must do?

Upvotes: 0

Views: 286

Answers (1)

Aziz Shaikh
Aziz Shaikh

Reputation: 16524

It looks like that the table containing checkboxes is echo'ed outside the form tag, which is why 'p' is not submitted with form post and $_POST['p'] is not found by PHP. Move your PHP code right after the form tag is created in HTML.

Upvotes: 1

Related Questions