jeudi 19 avril 2018

How to get multiple values from dynamic inputs in php

I made a system that generates a change major transcript for a student, the system generates the transcript with new major's courses automatically, and prints an empty text input. Here is the printing code:

        $realation = mysql_query("SELECT * FROM courserelation WHERE majorid= '$newid' AND typeid='1'");
    $type = "1";
    $counter= 0;
    while($row3 = mysql_fetch_array($realation)){
      $courseID = $row3["courseid"];

      $courses_ger = mysql_query("SELECT * FROM courses WHERE courseid= '$courseID'");
        while($row4 = mysql_fetch_array($courses_ger)){

          $ger .= '
                <form method="POST" action="">
                  <tr>
                    <td class="label" style="border-left: solid 0.5px ;">'.$row4["coursecode"].'</td>
                    <td colspan="2" class="label" style="border-left: solid 0.5px ;">'.$row4["coursename"].'</td>
                    <td class="label" style="border-left: solid 0.5px ;">'.$row4["credits"].'</td>
                    <td colspan="1" class="label" style="border-left: solid 0.5px ;">
                    <input type="text" name="oldger'.$counter.'"  autocomplete="off" list="majors" placeholder="New"></td>
                  </tr></form>';
$counter ++;

The Coordinator must enter the equivalent course in the empty field and submit it to database. My problem is i cant get the values from the input fields. I tried this code:

    $realation = mysql_query("SELECT * FROM courserelation WHERE majorid= '$newid' AND typeid='1'");
$type = "1";
$counter= 0;
while($row3 = mysql_fetch_array($realation)){
  $courseID = $row3["courseid"];

  $courses_ger = mysql_query("SELECT * FROM courses WHERE courseid= '$courseID'");
    while($row4 = mysql_fetch_array($courses_ger)){
      $ger .= '
            <form method="POST" action="">
              <tr>
                <td class="label" style="border-left: solid 0.5px ;">'.$row4["coursecode"].'</td>
                <td colspan="2" class="label" style="border-left: solid 0.5px ;">'.$row4["coursename"].'</td>
                <td class="label" style="border-left: solid 0.5px ;">'.$row4["credits"].'</td>
                <td colspan="1" class="label" style="border-left: solid 0.5px ;">
                <input type="text" name="oldger'.$counter.'"  autocomplete="off" list="majors" placeholder="New"></td>
              </tr></form>';

              echo $counter."<br>";
              $newcourse = $row4["coursecode"];
              echo "<center>".$newcourse." ";
              //////////////////
              $oldcourse = $_POST["oldger".$counter];
              echo $oldcourse."<br>";
 $counter ++;

    }

}

but the system reads only the first value. I'm attaching a picture with the error I have. Can you solve my problem please? Or do you have another way to perform this action? Thank You. Code Error




Aucun commentaire:

Enregistrer un commentaire