rajatgoel Posted May 18, 2009 Share Posted May 18, 2009 hi i am a newbee in this field i am not able to workout the following code the file name is hello.php code is <?php $k=1; echo '<form action="hello.php" method="POST">'; for($a=0;$a<=5;$a++) { echo "<input type = checkbox name=hell[] value=$a>"; echo $a; echo '<br>'; } echo '<input type="submit" >'; echo '</form>'; $k= $_POST[hell]; echo $k; ;?> the output is coming out as ARRAY, i dont understand why. the output should be the values that are checked Link to comment https://forums.phpfreaks.com/topic/158568-code-not-working/ Share on other sites More sharing options...
Axeia Posted May 18, 2009 Share Posted May 18, 2009 First off, please use tags when posting code (or even better if it's php ). This ensures indenting is preserved, increasing readability/chances of someone wanting to take a look at it. Second, the [] behind the name right here: <input type = checkbox name=hell[] value=$a> means that your values will be an array, which in the case of checkboxes is actually what you want. Also, unchecked values are lost so you can only get the checked values (which is what you wanted it seems). So instead of: $k= $_POST[hell]; echo $k; You'll need to loop trough the array, foreach( $_POST['hell'] as $value ) { echo $value.'<br/>'; } Link to comment https://forums.phpfreaks.com/topic/158568-code-not-working/#findComment-836315 Share on other sites More sharing options...
rajatgoel Posted May 18, 2009 Author Share Posted May 18, 2009 the solution you provided is not working i am again posting the code as you suggested the file is hello.php <?php $k=1; echo '<form action="hello.php" method="POST">'; for($a=0;$a<=5;$a++) { echo "<input type = checkbox name=hell[] value=$a>"; echo $a; echo '<br>'; } echo '<input type="submit" >'; echo '</form>'; $k= $_POST[hell]; echo $k; ;?> Link to comment https://forums.phpfreaks.com/topic/158568-code-not-working/#findComment-836317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.