title: get values from table and submit that values to another table mysql php
body: <p>so i want to input data into database table from a form (but not a filling form). after that i want to match the input to some table (table A) to get the id of the inputted data. and then i want to insert that id into another table... </p>
  
  <pre><code>&lt;?php    
  //submit attendance mahasiswa
      if(isset($_POST['buttonSubmitAbsenMahasiswa'])){
  
          foreach($_POST['inputStatusAbsen'] as $id_absensi=&gt;$status_absensi){
              $id_mahasiswa = $_POST['inputHiddenIDMahasiswa'][$id_absensi];
              $nim_mahasiswa = $_POST['inputHiddenNIMMahasiswa'][$id_absensi];
              $nama_mahasiswa = $_POST['inputHiddenNamaMahasiswa'][$id_absensi];
              $nama_matakuliah = $_POST['inputHiddenMataKuliahMahasiswa'][$id_absensi];
              $tanggal_absensi = date("Y-m-d");       
  
              //get matakuliah id
              $class_query = "SELECT * FROM matakuliah WHERE nama_matakuliah='".$nama_matakuliah."'";
              $class_id = mysqli_query($connection, $class_query);
  
              if($class_id){
                  while($class_id1 = $class_id-&gt;fetch_assoc()){
                      $class_id_fin = $class_id1['id_matakuliah'];
                  }
              }
  
              //get mahasiswa id
              $student_query = "SELECT * FROM data_mahasiswa WHERE nama_mahasiswa='".$nama_mahasiswa."'";
              $student_id = mysqli_query($connection, $student_query);
  
              if($student_id) {
                  while ($student_id1 = $student_id-&gt;fetch_assoc()) {
                      $student_id_fin = $student_id1['id_mahasiswa'];
                  }
              }
  
              //insert or update the record
              $query_insert_data_absensi = "INSERT INTO data_absensi VALUES ('$class_id_fin' , '$student_id_fin' , '$tanggal_absensi' , '$status_absensi')";
  
              mysqli_query($connection, $query_insert_data_absensi);
          }
      }
  ?&gt;
  </code></pre>
  
  <p>I want to match the inputted data to:</p>
  
  <pre><code>CREATE TABLE data_mahasiswa(
  id_mahasiswa int(255) PRIMARY KEY AUTO_INCREMENT,
  nim_mahasiswa varchar(255),
  nama_mahasiswa varchar(255),
  matakuliah_mahasiswa varchar(255));
  </code></pre>
  
  <p>or here:</p>
  
  <pre><code>CREATE TABLE matakuliah(
  id_matakuliah int(255) PRIMARY KEY AUTO_INCREMENT,
  nama_matakuliah varchar(255));
  </code></pre>
  
  <p>so that i can get the id for the corresponding table</p>
  
  <p>and then i want to insert the id to:</p>
  
  <pre><code>CREATE TABLE data_absensi(
  id_absensi int(255) PRIMARY KEY AUTO_INCREMENT,
  id_mahasiswa int(255),
  id_matakuliah int(255),
  tanggal_absensi date,
  status_absensi varchar(255));
  </code></pre>
  
  <p>the input is like this:</p>
  
  <pre><code>&lt;tr&gt;
    &lt;td&gt;
      &lt;?php echo $class['id_mahasiswa']; ?&gt;
      &lt;input type="text" hidden value="&lt;?php echo $class['id_mahasiswa']; ?&gt;" id="inputHiddenIDMahasiswa" name="inputHiddenIDMahasiswa[&lt;?php echo $i; ?&gt;]"&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;?php echo $class['nim_mahasiswa']; ?&gt;
      &lt;input type="text" hidden value="&lt;?php echo $class['nim_mahasiswa']; ?&gt;" id="inputHiddenNIMMahasiswa" name="inputHiddenNIMMahasiswa[&lt;?php echo $i; ?&gt;]"&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;?php echo $class['nama_mahasiswa']; ?&gt;
      &lt;input type="text" hidden value="&lt;?php echo $class['nama_mahasiswa']; ?&gt;" id="inputHiddenNamaMahasiswa" name="inputHiddenNamaMahasiswa[&lt;?php echo $i; ?&gt;]"&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;?php echo $class['matakuliah_mahasiswa']; ?&gt;
      &lt;input type="text" hidden value="&lt;?php echo $class['matakuliah_mahasiswa']; ?&gt;" id="inputHiddenMataKuliahMahasiswa" name="inputHiddenMataKuliahMahasiswa[&lt;?php echo $i; ?&gt;]"&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;div class="form-check form-check-inline"&gt;
        &lt;input class="form-check-input" type="radio" name="inputStatusAbsen[&lt;?php echo $i; ?&gt;]" value="Hadir"&gt;
        &lt;label class="form-check-label" for="inlineRadio1"&gt;Hadir&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="form-check form-check-inline"&gt;
        &lt;input class="form-check-input" type="radio" name="inputStatusAbsen[&lt;?php echo $i; ?&gt;]" value="Tidak hadir"&gt;
        &lt;label class="form-check-label" for="inlineRadio2"&gt;Tidak Hadir&lt;/label&gt;
      &lt;/div&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>where did i go wrong? p.s sorry for the non-english variables :|</p>