0

i'm gettimg this error on my page while modifying checkbox : Notice: Undefined index: selected in....[my file location] anyone know what had gone wrong?

this is part of my script:

 <?php
        if(!empty($konfirm))
        {
          foreach ($konfirm as $konfirm) { ?>
        <tr>
        <td style="text-align: center;"><?php if ($konfirm['selected']) { ?>
            <input type="checkbox" name="selected[]" value="<?php echo $konfirm['id']; ?>" checked="checked" />
            <?php } else { ?>
            <input type="checkbox" name="selected[]" value="<?php echo $konfirm['id']; ?>" />
            <?php } ?></td>

am i missing something? Please give me your direction.. Tell me if my description wasn't clear enough. Thank You very much.

2 Answers2

1

You are overwriting your variable $konfirm by declaring it as the "each" variable in your foreach statement. Rename this temporary variable to something else, and replace the name in the appropriate instances inside your loop iteration.

<?php
if (!empty($konfirm))
{
   foreach ($konfirm as $this_konfirm) { ?>
        <tr>
        <td style="text-align: center;"><?php if ($this_konfirm['selected']) { ?>
            <input type="checkbox" name="selected[]" value="<?php echo $this_konfirm['id']; ?>" checked="checked" />
            <?php } else { ?>
            <input type="checkbox" name="selected[]" value="<?php echo $this_konfirm['id']; ?>" />
            <?php } ?></td>
faintsignal
  • 1,828
  • 3
  • 22
  • 30
0

Check the existence of the checkbox form post. It will be set if it is checked or not set if it is not checked on the form.

<?php if (isset($konfirm['selected'])) { ?>
smozgur
  • 1,772
  • 1
  • 15
  • 23