Jump to content

Recommended Posts

Hi,

I have form that populates an array, but when I try and retrieve the contents of the array, they return as blank.

Form code is

$count="0";
While ($count<$num_rows){
?>
        <div>
        <label><?echo"$Part1[$count]"?></label>
        <input type="checkbox" name="<?echo"$Part1[$count]"?>" >
        </div>
<?
$count++;
}
?>
        <div>
        <button type="submit" class="btn" name="submit">Submit</button>
        </div> 

When I try and access the array with

$name = $_POST[Part1[0]];
echo"1 $name<br>";
$name = $_POST[Part1[1]];
echo"2 $name<br>";
$name = $_POST[Part1[2]];
echo"3 $name<br>";
$name = $_POST[Part1[3]];
echo"4 $name<br>";
$name = $_POST[[Part1[4]];
echo"5 $name<br>";

I get the exact results I entered in the form, but if I try and use ;

$num_rows="5";
$count="0";
While ($count<$num_rows){
        $name = $_POST[Part1[$count]];
        echo"1 $name<br>";   
        $count++;
}

I get blanks.

 

Any assistance for a new coder appreciated.

Jon

Link to comment
https://forums.phpfreaks.com/topic/311302-form-help/
Share on other sites

Thanks, that makes sense. The way I had it, the name would be changing each time it cycled rather than putting them into an array?

Not sure why I am still struggling with this....

<?PHP>

$count="0";
While ($count<$num_rows){
?>
        <div>
        <label><?echo"$Part1[$count]"?></label>
        <input type="checkbox" name="Part1[]"  >
        </div>
<?
$count++;
}
<?PHP>


$num_common_parts = "5";  
$count="0";
While ($count<$num_common_parts){
        $name = $_POST['Part1[$count]'];
        echo"Count $count Name $name<br>"; 
        $count++;
}

Still gives no output.

Quote

Count 0 Name
Count 1 Name
Count 2 Name
Count 3 Name
Count 4 Name

 

Link to comment
https://forums.phpfreaks.com/topic/311302-form-help/#findComment-1580503
Share on other sites

The returned value of the checkbox will exist only if checked. You should use 'isset' to see it if was checked then take appropriate action if it was. You also left off the value parameter. You need both as I showed you.

Edited by gw1500se
Link to comment
https://forums.phpfreaks.com/topic/311302-form-help/#findComment-1580526
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.