title: HTML in PHP - insert all value form while some of form display by loop
body: <p>I have a form that looks like:</p>
  
  <pre><code>|-----------------------|
  |Text                   |
  |(dropdown)             |
  ------------------------|
  |label (value = 1)      | //get this by loop using while
  |input                  | //get this by loop using while
  |-----------------------|
  |label (value = 2)      | //get this by loop using while
  |input                  | //get this by loop using while
  |-----------------------|
  |label (value = ...)    | //get this by loop using while
  |input                  | //get this by loop using while
  |-----------------------|
  |submit                 |
  </code></pre>
  
  <p>I dunno why my form just insert last value</p>
  
  <p><em><strong>example</strong></em></p>
  
  <ol>
  <li>choose dropdown value = 1</li>
  <li>add value of input = 80 on label 1</li>
  <li>add value of input = 79 on label 2</li>
  </ol>
  
  <p><em><strong>FYI</strong></em></p>
  
  <ol>
  <li>[ia] = dropdown value</li>
  <li>[ik] = label value</li>
  <li>[nn] = input value</li>
  </ol>
  
  <p>when I click the submit button with <code>print_r($_POST);</code> the output is <code>Array ( [ia] =&gt; 1 [ik] =&gt; 2 [nn] =&gt; 79 )</code></p>
  
  <p>I want to get</p>
  
  <pre><code>Array ( [ia] =&gt; 1 [ik] =&gt; 1 [nn] =&gt; 80 )
  Array ( [ia] =&gt; 1 [ik] =&gt; 2 [nn] =&gt; 79 )
  </code></pre>
  
  <p>this is my code about using <code>while</code> to display another form:</p>
  
  <pre><code>if($_POST){
  
      include_once 'includes/rangking.inc.php';
      $eks = new rangking($db);
  
      $eks-&gt;ia = $_POST['ia'];
      $eks-&gt;ik = $_POST['ik'];
      $eks-&gt;nn = $_POST['nn'];
  
      if($eks-&gt;insert()){
  ?&gt;
  &lt;div class="alert alert-success alert-dismissible" role="alert"&gt;
    &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
    &lt;strong&gt;Berhasil Tambah Data!&lt;/strong&gt; Tambah lagi atau &lt;a href="rangking.php"&gt;lihat semua data&lt;/a&gt;.
  &lt;/div&gt;
  &lt;?php
      }
  
      else{
  ?&gt;
  &lt;div class="alert alert-danger alert-dismissible" role="alert"&gt;
    &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
    &lt;strong&gt;Gagal Tambah Data!&lt;/strong&gt; Terjadi kesalahan, coba lagi.
  &lt;/div&gt;
  &lt;?php
      }
  }
  ?&gt;
  &lt;form method="post"&gt;
      &lt;div class="form-group"&gt;
      &lt;label for="ia"&gt;Alternatif&lt;/label&gt;
      &lt;select class="form-control" id="ia" name="ia"&gt;
          &lt;?php
          $stmt3 = $pgn1-&gt;readAll();
          while ($row3 = $stmt3-&gt;fetch(PDO::FETCH_ASSOC)){
              extract($row3);
              echo "&lt;option value='{$id_alternatif}'&gt;{$nama_alternatif}&lt;/option&gt;";
          }
          ?&gt;
      &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;?php
          $no=1;
          $stmt2 = $pgn2-&gt;readAll();
          while ($row2 = $stmt2-&gt;fetch(PDO::FETCH_ASSOC)){
              extract($row2);
              ?&gt;
              &lt;label for="ik"&gt;&lt;?php echo $nama_kriteria; ?&gt;&lt;/label&gt;
              &lt;input type="hidden" name="ik" id="ik" value=&lt;?php echo $id_kriteria ?&gt;&gt;
              &lt;input type="text" class="form-control" id="nn" name="nn"&gt;
          &lt;?php
          }
          ?&gt;
      &lt;/div&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;Simpan&lt;/button&gt;
      &lt;button type="button" onclick="location.href='rangking.php'" class="btn btn-success"&gt;Kembali&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><code>rangking.inc.php</code></p>
  
  <pre><code>function insert(){
  
          $query = "insert into ".$this-&gt;table_name." values(?,?,?,'','')";
          $stmt = $this-&gt;conn-&gt;prepare($query);
          $stmt-&gt;bindParam(1, $this-&gt;ia);
          $stmt-&gt;bindParam(2, $this-&gt;ik);
          $stmt-&gt;bindParam(3, $this-&gt;nn);
  
          if($stmt-&gt;execute()){
              return true;
          }else{
              return false;
          }
  
      }
  </code></pre>