Jump to content

code not working


rajatgoel

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.