0

I have problem with insert exam result of each student. the problem is how to insert the student result of every single exam.

Please take a look for my table :

exam table :

|id|exam_name|
| 1| run test|
| 2|swim test|

student table

|id|s_name|
| 1| roni |
| 2| mark |

let say roni pass the run test and failed on swim test so the result of roni in table exam_result will be like this : exam result table

|id_studen|id_exam|status|
| 1       | 1     | 1    |
| 1       | 2     | 0    |

this is my code : 1. for form input studetn exam result :

  <table class='wp-list-table widefat fixed striped posts'>
      <tr>
        <th class="bgth manage-column ss-list-width1">Participan Name</th>
          <th class="bgth manage-column ss-list-width1">Complited Pool Requirement</th>
          <th class="bgth manage-column ss-list-width1">Complited Theory Exam</th>
          <th class="bgth manage-column ss-list-width1">Medical Sertificate Checked</th>
    <th class="bgth manage-column ss-list-width" colspan="2">Action</th>
      </tr>
  <input type='hidden' name='exam_total' value='3'><input type='hidden' name='exam_names' value='[{"id":"1","exam_name":"Complited Pool Requirement"},{"id":"2","exam_name":"Complited Theory Exam"},{"id":"3","exam_name":"Medical Sertificate Checked"}]'><tr><td class='manage-column ss-list-width'>Handri angga riawan
        <input type='hidden' value='1' name='x-id[]'></td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='status0[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='1' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='status1[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='2' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='status2[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='3' >
          </td><td class='manage-column ss-list-width'><a href='#'>Delete Participan</a></td></tr><td class='manage-column ss-list-width'>Suyadman
        <input type='hidden' value='2' name='x-id[]'></td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='status0[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='1' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='status1[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='2' >
          </td><td class='manage-column ss-list-width'>
          <input type='checkbox' name='status2[]' value='1'>check if pass
          <input type='hidden' name='id_exam[]' value='3' >
          </td><td class='manage-column ss-list-width'><a href='#'>Delete Participan</a></td></tr></table><p><input type="submit" id="btn" name="p-submitted" value="Save Result"></p></form>

and this is how i get the value of each student result :

if ( isset( $_POST['p-submitted'] ) ) {
        $all = array();
        $exam_total = $_POST['exam_total'];
        $exam_namer = $_POST['exam_names'];
        $idp = $_POST['x-id'];
        $idxa = $_POST['id_exam'];
        $exam_names = json_decode(stripslashes($exam_namer));

        $pu = array();
        for($a=0;$a<$exam_total-1; $a++){
        for($i=0; $i<$exam_total; $i++){

      $status = isset($_POST['status'.$i]) ? $_POST['status'.$i] : 0 ;
      echo "INSERT INTO DB VALUES($id,$xid,$status)";
      }
}

As you can see i try a lot of and still not working i want to insert result of student exam result, so the sql look like this : insert into table values (id_student, exam_id, status); but for information i want the exam is depending on exam table s...

please help me :)

Strawberry
  • 33,750
  • 13
  • 40
  • 57
NinjaCode
  • 65
  • 7
  • please post your code without the commented out section. Please post your table as show create table – e4c5 Nov 04 '16 at 05:58

1 Answers1

0

For starters you are not trying to insert any data into a database, you are echoing the statement out echo "INSERT INTO DB VALUES($id,$xid,$status)";.

Secondly the statement is incomplete, the format is INSERT INTO table ( COL1, COL2) VALUES (VAL1, VAL2);

Moving on from that you need to have a look into either mysqli or better still PDO - https://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059

This will provide you will all the information you need to be able to insert he data into a database safely.

Blinkydamo
  • 1,582
  • 9
  • 20
  • yes, i just make a sure the sql statement is correct before i insert it thats why i echo out the sql. but thanks for comment – NinjaCode Nov 04 '16 at 08:21