Postingan lainnya
Warning: Undefined variable $kode_barang in C:\xampp\htdocs\inventory\supplier.php on line 186
Kesalahan Detailnya :
1.) Warning: Undefined variable $kode_barang in C:\xampp\htdocs\inventory\supplier.php on line 186
2.) Notice: Object of class mysqli_result could not be converted to int in C:\xampp\htdocs\inventory\supplier.php on line 187
3.) Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\inventory\supplier.php:187 Stack trace: #0 C:\xampp\htdocs\inventory\supplier.php(187): mysqli_num_rows(true) #1 {main} thrown in C:\xampp\htdocs\inventory\supplier.php on line 187
Code Line 186 :
$cek = mysqli_query($connect, "SELECT * FROM barang WHERE kode_barang = '$kode_barang=null'");
Code Line 187 :
if (mysqli_num_rows($cek > 0))
Full Code :
<?php
if (isset($_POST['submit'])) {
$kode = $_POST['kode'];
$kode_supplier = $kode.$newKode;
$nama = $_POST['nama'];
$kota = $_POST['kota'];
$telp = $_POST['telp'];
$alamat = $_POST['alamat'];
$cek = mysqli_query($connect, "SELECT * FROM barang WHERE kode_barang = '$kode_barang=null'");
if (mysqli_num_rows($cek > 0)) {
$_SESSION['danger'] = "Maaf, Kode barang tersebut sudah ada, mohon coba lagi";
}
else {
$query = mysqli_query($connect, "
INSERT INTO supplier(kode_supplier, nama_supplier, alamat_supplier, telp_supplier, kota_supplier)
VALUES ('$kode_supplier', '$nama', '$alamat', '$telp', '$kota') ");
if ($query) {
$_SESSION['success'] = "Data berhasil dimasukkan";
echo "<script>location.replace('supplier.php');</script>";
}
else {
$_SESSION['danger'] = "Error saat memasukkan data";
}
}
}
?>
1 Jawaban:
Jawaban Terpilih
<div>Coba baris ini :</div><pre> $cek = mysqli_query($connect, "SELECT * FROM barang WHERE kode_barang = '$kode_barang=null'");
if (mysqli_num_rows($cek &gt; 0)) {
$_SESSION['danger'] = "Maaf, Kode barang tersebut sudah ada, mohon coba lagi";
}</pre><div><br>diubah menjadi :</div><pre> $cek = mysqli_query($connect, "SELECT * FROM barang WHERE kode_barang = '$kode'"); //Karena diatas nama variabelnya $kode
if (mysqli_num_rows($cek) &gt; 0) { //tanda &gt; 0 harusnya diluar tanda tutup kurung pertama
$_SESSION['danger'] = "Maaf, Kode barang tersebut sudah ada, mohon coba lagi";
}</pre><div><br>Semoga berhasil.</div>