0

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?

1 Answer 1

1

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.

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

1 Comment

You are right! thank you very much now it works:D I echoed this:echo $_POST['p'][$key];

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.