title: Mysqli insert into multiple table with auto increment
body: <p>hello i tried using mysqli to fetch autoincrement id from the first table to insert it for second table, this is my database design for each table</p>
  
  <p>Table users </p>
  
  <pre><code>  id_user  PK auto-inc
    username 
    password
    nama
    role
    status
  </code></pre>
  
  <p>table siswa</p>
  
  <pre><code>  id_siswa PK auto-inc
    id_tingkatan 
    nama_siswa
    jk_siswa
    hp_siswa
    nama_ortu
    jk_ortu
    hp_ortu
    id_user 
  </code></pre>
  
  <p>this is what i have tried </p>
  
  <pre><code>$query = "INSERT INTO users
                          (username, password, nama, role, status) 
                   VALUES ('$name','$password','$nama','$role','$status')";
  $koneksi-&gt;query($query);
  
  $query = "INSERT INTO siswa
                          (id_tingkatan, nama_siswa, jk_siswa, hp_siswa, 
                           nama_ortu, jk_ortu, hp_ortu, id_user) 
                   VALUES ('$tingkatan','$nama','$jksiswa','$hpsiswa',
                           '$namaortu','$hportu', $koneksi-&gt;insert_id)";
  $koneksi-&gt;query($query);
  </code></pre>
  
  <p>the data is inserted into users table but not to siswa table, any suggestion to fix this?</p>
  
  <p>edit : overlooked variable only ($jkortu) fixed now, thanks</p>