title: multiple value insertion from a form
body: <p>I am having form with a table with three columns namely Roll_No, Name and Marks. I am fetching the Roll_no and Name from the database. The teacher only has to enter the marks in the form against the respective student's roll no and name. I coded as shown below, but only the last value entered is getting set for all the students in the database. Its inserting the sid and roll no correctly but creating problem with marks. My database  structure for marks is sid, roll_no, marks.</p>
  
  <p>Here is my code: correct me where am going wrong please.</p>
  
  <pre><code>&lt;form method="post" action=""&gt;
  &lt;table width="900" height="49" border="1" cellpadding="0" cellspacing="0" align="center" &gt;
   &lt;?php if(isset($_SESSION['response']))
        { 
  echo "&lt;tr&gt;&lt;td colspan=\"7\"&gt;".$_SESSION['response']."&lt;/td&gt;&lt;/tr&gt;";    unset($_SESSION['response']);} ?&gt;
  
      &lt;tr&gt;
          &lt;td align="center" width="20"&gt; Roll No.&lt;/td&gt;
          &lt;td align="center" width="200"&gt; Name&lt;/td&gt;
          &lt;td align="center" width="20"&gt; Marks&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;input type="submit" name="next" value="submit" /&gt;&lt;/tr&gt;
      &lt;?php
      $sub = $_GET['sid'];
  
      $result = mysql_query("select * from student_record_by_faculty where sid='$sub'");
      $numrows = mysql_num_rows($result);
      if($numrows!=0)
  {
          while($r=mysql_fetch_array($result))
          {
              $r2=mysql_fetch_array(mysql_query("select name from login where username='$r[reg_no]'"));
  
  
      ?&gt;
      &lt;tr&gt;
      &lt;td align="center"&gt;&lt;?php echo $r['reg_no']; ?&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;?php echo $r2['name']; ?&gt;&lt;/td&gt;
      &lt;td align="centre"&gt;&lt;input type="number" name="marks" /&gt;
      &lt;?php
      if(isset($_POST['next']))
      {
          $marks = $_POST['marks'];
          $q=mysql_query("INSERT INTO marks(sid, reg_no, first_sessional) VALUES('$sub','$r[reg_no]','".$_POST['marks']."')");
          echo $q;
          if($q)
          {       echo "marksheet updated you are being directed to marksheet page";
               sleep(2);
                  header("Location:marksheet.php");
          }
      }
      ?&gt;    
      &lt;/td&gt;&lt;/tr&gt; 
  
  
    &lt;?php                         
       }
  }
      else
      {
     die('Error: ' . mysql_error());
  }
  //mysqli_close($con);*/
  ?&gt; 
  </code></pre>
  
  <p>
     </p>