title: While loop for inserting values for each rows into the database using single submit button
body: <p>Currently, I am working on the attendance form. In this interface, it consists rows of student(get from student table). The list of students are viewed in the table. the first column is NO, second column in Birth No, third STudent Name, forth Attendance. in column attendance, there are three radio button which is PT, AT, and MC which their value is present, absent, and mc respectively. The outside of the table, there is a submit button. Teacher needs to click which attendance of the student, either pt, at or mc. Teacher needs to click for all students. When submit button clicked by teacher, attendance of the students will be inserted into the database. When I execute code below, there nothing value is inserted in the database. Can some please help me to figure it out where i went wrong? I worked on this code for past 2 weeks yet still not getting an expected result. Thank you.</p>
  
  <pre><code>$getdata = mysql_query("select * from student where 
       class = '$class' order by name ")     or die(mysql_query);
  
  if (isset($_POST['submit'])){
  $id = 1;
  while($row = mysql_fetch_assoc($getdata)){
      if(isset($_POST['a'.$id])) {
          $status = $_POST['a'.$id];      
          if(!empty($status)){
              if(($status == "present" || $status == "mc")){
                  $attend = 1;
              }
              else if($status == "absent"){
                  $attend = 0;
              }
              $query = "INSERT INTO attendance(birth_no, date, status, attend) 
              VALUES ('$birth_no','$date','$status','$attend')";
              if($query_run = mysql_query($query)){
                  echo 'Insert attendance done';
              }
              else{
                  echo'Attendance not inserted.';
              }                   
          }
          else{
              echo 'Please enter all fields';
          }
      }
      $id ++;
  }
  }
  else {
  ?&gt;   
  &lt;form action="addattend.php" method = "POST"&gt;
  &lt;table&gt;
  &lt;?php
  $id = 1;
  while($row = mysql_fetch_assoc($getdata)){
      $birth_no= $row['birth_no'];
      $name = $row['name'];
  ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;center&gt;&lt;?php echo $id ?&gt;&lt;/center&gt;&lt;/td&gt;
          &lt;td&gt;&lt;center&gt;&lt;?php echo $date ?&gt;&lt;/center&gt;&lt;/td&gt;
          &lt;td&gt;&lt;center&gt;&lt;?php echo $birth_no ?&gt;&lt;/center&gt;&lt;/td&gt;
          &lt;td&gt;&lt;center&gt;&lt;?php echo $name ?&gt;&lt;/center&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;input type="radio" name="a&lt;?php echo $id; ?&gt;" value="present"&gt;PT
              &lt;input type="radio" name="a&lt;?php echo $id; ?&gt;" value="absent"&gt;AT
              &lt;input type="radio" name="a&lt;?php echo $id; ?&gt;" value="mc"&gt;MC
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;?php
      $id ++;
  } // end while
  ?&gt;
  &lt;/table&gt;
  &lt;center&gt;&lt;input type="submit" name="submit" value="Submit"&gt;&lt;/center&gt;
  &lt;/form&gt; &lt;!-- end the form here --&gt;
  &lt;?php    
  } // end else
  ?&gt;
  </code></pre>
  
  <p>this is what i meant about the interface(picture below)</p>
  
  <p><img src="https://i.stack.imgur.com/tnUab.png" alt="enter image description here"></p>
  
  <p>for every row, there are 3 radio buttons. The list of student was retrieved from the database. Teachers need to select the attendance for all students. with a single submit button, All the attendance will be inserted in the database with birth_no, date(selected earlier by teacher) and also $attend which is assigned after attendance selected. </p>