-2

I'm new in programming, and i don't know why it doesn't work. I use the same code for my other input form, and that code work just fine. But, for this form, it's not. The form is pretty much same, so, that's why i totally do not understand why it's not working.

This is the php code where the message error come from. I wish you can help me. Thank you so much.

<?php
session_start();
require 'db.php';

 $kodeunit = $_SESSION["KodeUnit"];
 $namaunit = $_POST['namaunit'];
 $alamat = $_POST['alamat'];
 $pimpinanunit = $_POST['pimpinanunit'];
 $kuasaanggaran = $_POST['kuasaanggaran'];
 $pembuatkomitmen = $_POST['pembuatkomitmen'];
 $penanggungjawab = $_POST['penanggungjawab'];
 $sql   = "UPDATE unit_organisasi SET Nama_Unit = '$namaunit', Pimpinan_Unit = '$pimpinanunit', Alamat = '$alamat', Kuasa_Anggaran = '$kuasaanggaran', Pembuat_Komitment = '$pembuatkomitmen', Penanggungjawab = '$penanggungjawab' WHERE Kode_Unit = '$kodeunit'";
 
 if((!strlen(trim($namaunit))) || (!strlen(trim($alamat))) || (!strlen(trim($pimpinanunit))) || (!strlen(trim($kuasaanggaran))) || (!strlen(trim($pembuatkomitmen))) || (!strlen(trim($penanggungjawab)))){
  echo "<script>alert('Data Belum Lengkap!')</script>";
  header ('Location:inpudataunit.php');
 }
 else{
  $result = $conn->query($sql);
  if($result === TRUE){
   echo "Berhasil diinput";
  }
 }
 
?>
Adinda
  • 7
  • 2
  • show your form and error message – Sofyan Thayf Feb 11 '18 at 03:54
  • Your query is using potentially unsafe user-supplied data directly. You should change your process to use prepared statements with mysqli or pdo. If you want to avoid these types of Notices, you'll need to use conditionals with `isset()` or `!empty()` to determine if the script should deadend or proceed as planned. We cannot help you because you have not provided the submission form markup. I don't speak Indonesian or whatever language this is, so I can't tell if there are any easy typos to find. Please improve your question, otherwise it will be closed as "Why isn't this working". – mickmackusa Feb 11 '18 at 04:07
  • Also, `UPDATE` can return a `true` response and affect `0` rows. Your success check should be improved. – mickmackusa Feb 11 '18 at 04:11

1 Answers1

-2

Seems like your form has no input field named namaunit . Check your form input name.

Vincent
  • 84
  • 6