Foreach is picking the first checkbox only if checked
<p>I am working on the following code in order to pick checkboxes from a form. If i check the first checkbox everything works great. If i check another checkbox i get the "Undefined index" error when sending <code>bulkcopy</code> form. Keep in mind that i am getting the checkboxes with post method and the submit button is above the checkboxes due to the complexity of the location of the form and the fields. What i need essentially is to pick multiple checkboxes and add certain values to the database.</p>

<pre><code>&lt;?php //bulkcopy.php

  session_start();
  if($_SESSION['admin_logged_in'] != true){
    header("Location:login.html");
    exit();
  }
  include 'db.php';

  $from = mysql_real_escape_string($_GET['from']);
  $room = mysql_real_escape_string($_POST['room']);

  if(!empty($_POST['id'])) {
    foreach($_POST['id'] as $check) {
      $id = $check;

      $sel = mysql_query("select * from $from where id = '$id' limit 1 ") or die(mysql_error());

      while($row = mysql_fetch_array($sel)){
        $preview = $row['preview'];
        $text = $row['text'];
        $title = $row['title'];
        $images = $row['images'];
      }

      $ins = mysql_query("insert into $room (id, preview, text, title, images) values (' ', '$preview', '$text', '$title', '$images') ") or die(mysql_error());

    }

    header("Location:admin.php");
  }

?&gt;
</code></pre>

<p>The code of the form can be found below:</p>

<pre><code>&lt;form class="form-inline" name="bulkcopy" method="post" action="bulkcopy.php?from=sights"&gt; &lt;b&gt;Bulk Copy:&lt;/b&gt; 
    &lt;select name='room' class="form-control"&gt;
        &lt;option&gt;Select...&lt;/option&gt;
        &lt;option value="Orhan"&gt;Orhan&lt;/option&gt;
        &lt;option value="Deniz"&gt;Deniz&lt;/option&gt;
        &lt;option value="Irini"&gt;Irini&lt;/option&gt;
        &lt;option value="Katina"&gt;Katina&lt;/option&gt;
        &lt;option value="Gulbin"&gt;Gulbin&lt;/option&gt;
        &lt;option value="Mihalis"&gt;Mihalis&lt;/option&gt;
    &lt;/select&gt;
    &lt;input class="btn btn-primary" type="submit" name="submit" value="Go"&gt;&lt;br /&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;table class="table table-bordered table-striped"&gt;
    &lt;th&gt;Entry Name&lt;/th&gt;
    &lt;th&gt;Display Order&lt;/th&gt;
    &lt;th&gt;Copy to...&lt;/th&gt;
    &lt;th&gt;Status&lt;/th&gt;
    &lt;th&gt;Image&lt;/th&gt;
    &lt;th&gt;Edit&lt;/th&gt;
    &lt;th&gt;Delete&lt;/th&gt;
    &lt;th&gt;Duplicate&lt;/th&gt;

    &lt;?php while($row = mysql_fetch_array($sel)) { ?&gt;
    &lt;tr&gt;
        &lt;td&gt;
            &lt;input type="checkbox" name="id[]" value="&lt;?php echo $row['id']; ?&gt;"&gt;
            &lt;/form&gt;
            &lt;?php echo $row['title']; ?&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;form name="order" method="post" action="sightorder.php?id=&lt;?php echo htmlspecialchars($row['id']); ?&gt;"&gt;
                &lt;div class="col-md-4"&gt;
                    &lt;input class="form-control" type="number" name="order" value="&lt;?php echo htmlspecialchars($row['ordernum']); ?&gt;"&gt;
                &lt;/div&gt;
                &lt;div class="col-sm-3"&gt;
                    &lt;input type="submit" name="submit" value="Set Order" class="btn btn-primary"&gt;
                &lt;/div&gt;
            &lt;/form&gt;
        &lt;/td&gt;
        &lt;td&gt;

            &lt;form name="copyto" method="post" action="copyto.php?from=sights&amp;id=&lt;?php echo htmlspecialchars($row['id']); ?&gt;"&gt;
                &lt;input type="checkbox" name="room[]" value="Orhan"&gt; O -
                &lt;input type="checkbox" name="room[]" value="Deniz"&gt; D -
                &lt;input type="checkbox" name="room[]" value="Irini"&gt; I -
                &lt;input type="checkbox" name="room[]" value="Katina"&gt; K -
                &lt;input type="checkbox" name="room[]" value="Gulbin"&gt; G -
                &lt;input type="checkbox" name="room[]" value="Mihalis"&gt; M 
                &lt;input type="submit" name="submit" value="Copy" class="btn btn-primary"&gt;
            &lt;/form&gt;

        &lt;/td&gt;
        &lt;td&gt;
            &lt;a href="sightstatus.php?id=&lt;?php echo htmlspecialchars($row['id']); ?&gt;&amp;status=&lt;?php echo $row['status']; ?&gt;"&gt;&lt;?php if($row['status'] == 1){ ?&gt;&lt;i class="fa fa-check fa-lg"&gt;&lt;/i&gt;&lt;?php }else{ ?&gt;&lt;i class="fa fa-times fa-lg"&gt;&lt;/i&gt;&lt;?php } ?&gt;&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;a href="sightimages.php?id=&lt;?php echo $row['id']; ?&gt;"&gt;&lt;i class="fa fa-image fa-lg"&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;a href="editsight.php?id=&lt;?php echo htmlspecialchars($row['id']); ?&gt;"&gt;&lt;i class="fa fa-edit fa-lg"&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;a onclick="return confirmDelete()" href="delsight.php?id=&lt;?php echo htmlspecialchars($row['id']); ?&gt;"&gt;&lt;i class="fa fa-trash fa-lg"&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;a href="duplicatesight.php?id=&lt;?php echo htmlspecialchars($row['id']); ?&gt;"&gt;&lt;i class="fa fa-copy fa-lg"&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php } ?&gt;
&lt;/table&gt;
</code></pre>

<p>Any help would be greatly appreciated. 
Thanks.</p>