title: calculate student total marks and insert that total in another table with the id of that student together
body: <p>I'm developing a simple student information system, for now i have 300 students and six subjects, so when i want to add marks obtained by each student i use html form and php script to add those marks, for each student i add marks for six subjects that is one subject at a time, so i'm asking if there is the way where by php can allow me retrieve one student and add all the marks for the six subjects at once and then take another and so on. Also i want to calculate total marks for each student and store those total in another table with respective student id so that i can know who is the first student and who is the last by using that total marks of each student.</p>
  
  <p>here is the way i'm doing right now</p>
  
  <pre><code>&lt;?php error_reporting(E_ALL ^ E_NOTICE); ?&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;div&gt;
  &lt;div&gt;
  &lt;form action="connmarks.php" method="post"&gt;
      &lt;table&gt;
      &lt;tr&gt;&lt;td colspan="6"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;&lt;p&gt;Adding Student Results&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;
      &lt;td width="9%"&gt;Student Code&lt;?php echo $mstudentcode;?&gt;&lt;/td&gt;
      &lt;td width="17%"&gt;&lt;input name="student_code" type="text" size="30" value="&lt;?php echo $studentcode;?&gt;" /&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;
      &lt;td width="10%"&gt;Subject Code&lt;?php echo $msubjectcode;?&gt;&lt;/td&gt;
      &lt;td width="18%"&gt;&lt;input name="subject_code" type="text" size="30"  value="&lt;?php echo $subject_code;?&gt;"/&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;tr&gt;
      &lt;td width="12%"&gt;Marks&lt;?php echo $mmark;?&gt;&lt;/td&gt;
      &lt;td width="34%"&gt;&lt;input name="mark" type="text" size="30" value="&lt;?php echo $mark;?&gt;"/&gt;&lt;/td&gt;
  
      &lt;/tr&gt;
        &lt;td&gt;&amp;nbsp;&lt;/td&gt;
        &lt;td&gt;&amp;nbsp;
        &lt;/td&gt;
      &lt;/tr&gt;
       &lt;tr&gt;&lt;td colspan="4"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td colspan="6"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td colspan="6"&gt;&lt;input type="submit" name="save" value="Add Marks" /&gt;&lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr&gt;&lt;td colspan="6"&gt;&lt;?php echo $sms1.$sms.$sms2;?&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;/table&gt;
      &lt;/form&gt;
      &lt;/div&gt;
      &lt;div id="footer"&gt;Copyright &lt;?php echo date("Y", time()); ?&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
  &lt;?php error_reporting(E_ALL ^ E_NOTICE); ?&gt;
  &lt;?php
  session_start();
  if(isset($_POST['save']))
  {
  //  validating student code
      if(empty($_POST['student_code']))
      {
          $mstudentcode='&lt;font color="red"&gt;&lt;b&gt;**&lt;/b&gt;&lt;/font&gt;';
      }
      else
      {
          $student_code=$_POST['student_code'];
      }
  //  validation for kiswahili subject
      if(empty($_POST['subject_code']))
      {
          $msubjectcode='&lt;font color="red"&gt;&lt;b&gt;**&lt;/b&gt;&lt;/font&gt;';
      }
      else
      {
          $subject_code=$_POST['subject_code'];
      }
  // validating english subject
      if(empty($_POST['mark']))
      {
          $mmark='&lt;font color="red"&gt;&lt;b&gt;**&lt;/b&gt;&lt;/font&gt;';
      }
      else
      {
          $mark=$_POST['mark'];
      }
  // checking if there is any error message, if no error proceed, if there is error, display the error
  //  Then exit the script and redirect at the same page
      if($mstudentcode||$msubjectcode||$mmark||$sms)
      {
          $sms1='&lt;font color="red"&gt;&lt;b&gt;Error found,please check **&lt;/b&gt;&lt;/font&gt;&lt;br/&gt;';
          include 'addmarks.php';
          exit;
      }
  // if there is no error include connection file
      if($student_code&amp;&amp;$subject_code&amp;&amp;$mark)
      {
  //      include 'mysqli_connect.php';
        require_once ('../../mysqli_connect.php');
          $addmarks= "insert into result(student_code,subject_code,mark) values ('".$student_code."','".$subject_code."','".$mark."')";
          $k = mysqli_query($dbc, $addmarks);
          if ($k)
          {
         $sms1='&lt;font color="green"&gt;&lt;b&gt;Student Marks Submitted Successfully&lt;/b&gt;&lt;/font&gt;&lt;br/&gt;';
              include 'addmarks.php';
                          exit;
          }
          else
          {
              $sms1='&lt;font color="red"&gt;&lt;b&gt;Failed To Add Student Marks&lt;/b&gt;&lt;/font&gt;&lt;br/&gt;';
              include 'addmarks.php';
                          exit;
          }
      }
      }
  ?&gt;
  </code></pre>