0

this code for edit data not for add data, problem with data editing. when i update the dropdown there is no problem but it doesn't change the value in the input, the second data comes in but the first one doesn't. when I add data there is no problem only when editing it


 for ($i = 0; $i < $total; $i++) {

        $id_jenispengujian = $id_user[0] . $nomor[0] . $jenis[$i];
        $hasil = mysqli_query(konek::konekdb(), "INSERT INTO pemohon_uji 
          (id_jenispengujian,
          jenis_pengujian,
          jumlah_uji, 
          id_user, 
          no_surat) values
          ( 
            '$id_jenispengujian',
            '$jenis[$i]',
            '$jumlah[$i]',
            '$id_user[0]',
            '$nomor[0]'
          )ON DUPLICATE KEY UPDATE 
        id_jenispengujian = '$id_jenispengujian',
        jenis = '$jenis[$i]',
          jumlah_uji = '$jumlah[$i]',
          id_user = '$id_user[0]',
          no_surat = '$nomor[0]'");
    };



[enter image description here](https://i.stack.imgur.com/YC0Ha.png)

both arrays are inputted properly

  • Your script is vulnerable to [SQL Injection Attack](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Even if [you are escaping variables, its not safe](https://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string%5D)! You should always use [prepared statements and parameterized queries](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) in either MYSQLI or PDO instead of concatenating variables into the query. – Barmar Dec 29 '22 at 20:29

0 Answers0