I’m having a problem getting the selected weight value on a dynamic form I’m creating. Here’s the code for the get_recomendation.php form:
<form action="./get-recomendation-admin.php" method="POST" class="row justify-content-center">
<?php $kriteria = $connection->query("SELECT * FROM kriteria"); while ($data = $kriteria->fetch_assoc()): ?>
<div class="col-12 my-4 my-options">
<label for="kriteria" class="form-label"><?=$data["nama"]?></label>
<input type="hidden" class="form-control" id="id_kriteria" name="id_kriteria" readonly value="<?php echo $data['id_kriteria']; ?>">
<input type="hidden" class="form-control" id="nama_kriteria" name="nama_kriteria" readonly value="<?php echo $data['nama']; ?>">
<select class="form-select" id="bobot_kriteria" required="">
<option value="" disabled selected>Pilih Sub Kriteria</option>
<?php $t_kriteria = $connection->query("SELECT * FROM tingkat_kriteria"); while ($row = $t_kriteria->fetch_assoc()): ?>
<option value="<?=$row["bobot"]?>"><?=$row["nama"]?></option>
<?php endwhile; ?>
</select>
</div>
<?php endwhile; ?>
<div class="d-flex justify-content-center my-5">
<button class="btn btn-dark mb-3 shadow-button fs-6 px-5 py-3" type="submit">Cari Rekomendasi</button>
</div>
</form>
I tried to do a var_dump using the following code
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
var_dump($_POST['nama_kriteria']);
var_dump($_POST['bobot_kriteria']);
}
result
string(5) "Harga"
Notice: Undefined index: bobot_kriteria in E:Program Filesxampphtdocsxxxxxxxxget-recomendation-admin.php on line 12
NULL
As for the output I want it’s like
Jenis Processor
10
Kapasitas RAM
20
XXXXX
XX
....
For the database I use like this
table tingkat_kriteria
| id | nama | bobot |
|:----: |:---------------:|:-----:|
| 1 | Sangat Penting | 30 |
| 2 | Cukup Penting | 25 |
| 3 | Cukup | 20 |
| 4 | Kurang Penting | 15 |
| 5 | Tidak Penting | 10 |
and for the criteria table like this
table kriteria
| id | nama |
|:----: |:---------------:|
| 2 | Jenis Processor |
| 3 | Kapasitas RAM |
| 4 | Jumlah Drive |
| 8 | Harga |