I make 2 forms in 3 files: loginMHS.php, inputPerwalian.php, insertMataKuliah.php.
I have 4 tables in database: mahasiswa, matakuliah, kelas, mahasiswa_kelas.
mahasiswa table has these fields:
nrp | nama | pass | jatah_sks | foto_profil
matakuliah table has these fields:
kode_mk | nama | jumlah_sks | deskripsi
kelas table has these fields:
kode_kelas | kode_mk | kode_periode | nama_kelas
mahasiswa_kelas table has these fields:
nrp | kode_kelas
First, loginMHS.php showed up. It has a form, which has an input stored in var $nrp (from mahasiswa table). After login, inputPerwalian.php showed up. It has a form too, which has inputs stored in var $kodeMK (from matakuliah table) & $namaKelas (from kelas table). Then, the inputs will be inserted to table mahasiswa_kelas.
This is my code (the inputs can't be stored to DB, but it shows no error):
$sql = "select kode_kelas from kelas inner join mahasiswa_kelas"
. " on kelas.kode_kelas = mahasiswa_kelas.kode_kelas"
. " where nama_kelas=" . $namaKelas;
$result = mysqli_query($link, $sql);
$sql2 = "insert into mahasiswa_kelas (nrp, kode_kelas)"
. " values ($nrp, $result)";
$result2 = mysqli_query($link, $sql2);
$row2 = mysqli_fetch_array($result2);
I don't know how to insert it, while the data inputed is from another table. Because, from what I know is, I can't use inner join in insert query. How to solve it? Please explain your answer. Thanks