title: How to convert foreach() Mysql select into HTML form
body: <p>I am working on a small course registration system. I have a table called 20182019carryovertbl I select students carry over fron the table and its working well. I need to convert the selected info to an HTML form with submit button( This will go into another table 20192020coursestbl). How d i set name for my inputs </p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Register course&lt;/th&gt;
        &lt;th&gt;Course Title&lt;/th&gt;
        &lt;th&gt;Corse Code&lt;/th&gt;
        &lt;th&gt;Unit&lt;/th&gt;
        &lt;th&gt;Lecturer&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tbody&gt;
  
      &lt;?php $sql = "SELECT * from  20182019carryovertbl WHERE matricno = '$matno' ";
  $query = $dbh -&gt; prepare($sql);
  $query-&gt;execute();
  $results=$query-&gt;fetchAll(PDO::FETCH_OBJ);
  $cnt=1;
  if($query-&gt;rowCount() &gt; 0)
  {
  foreach($results as $result)
  {               ?&gt;
      &lt;tr&gt;
        &lt;td&gt; &lt;input type="checkbox" name="reg1" value="1" class="custom-control-input"&gt;&lt;/td&gt;
        &lt;td&gt;
          &lt;?php echo htmlentities($result-&gt;coursetitle);?&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;?php echo htmlentities($result-&gt;coursecode);?&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;?php echo htmlentities($result-&gt;unit);?&gt;
        &lt;/td&gt;
        &lt;td&gt;
          &lt;?php echo htmlentities($result-&gt;lecturer);?&gt;
        &lt;/td&gt;
  
      &lt;/tr&gt;
      &lt;?php $cnt=$cnt+1; }} ?&gt;
  
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>