Postingan lainnya
salah dimana ya gan?
<?php
session_start();
if($_SESSION){
if($_SESSION['role'] == 'admin'){
}else{
header('location:../index.php');
}
}else{
header('location:../index.php');
}
$conn = mysqli_connect('localhost','root','','ujikom_laundry');
function ambildata($conn,$query){
$data = mysqli_query($conn,$query);
if (mysqli_num_rows($data) > 0) {
while($row = mysqli_fetch_assoc($data)){
$hasil[] = $row;
}
return $hasil;
}
}
function bisa($conn,$query){
$db = mysqli_query($conn,$query);
if($db){
return 1;
}else{
return 0;
}
}
function ambilsatubaris($conn,$query){
$db = mysqli_query($conn,$query);
return mysqli_fetch_assoc($db);
}
function hapus($where,$table,$redirect){
$query = 'DELETE FROM ' . $table . ' WHERE ' . $where;
echo $query;
}
?>
Tanggapan
Errornya Apa Bang?
Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\laundry1\admin\functions.php:41 Stack trace: #0 C:\xampp\htdocs\laundry1\admin\functions.php(41): mysqli_fetch_array(false) #1 C:\xampp\htdocs\laundry1\admin\transaksi_tambah.php(15): ambilsatubaris(Object(mysqli), 'SELECT nama_out...') #2 {main} thrown in C:\xampp\htdocs\laundry1\admin\functions.php on line 41
line 41 : return mysqli_fetch_array($db);
1 Jawaban:
<pre><?php session_start();
if($_SESSION){ if($_SESSION['role'] == 'admin'){
}else{
header('location:../index.php');
}
}else{ header('location:../index.php'); }
$conn = mysqli_connect('localhost','root','','ujikom_laundry');
function ambildata($conn,$query){ $data = mysqli_query($conn,$query); if (mysqli_num_rows($data) > 0) { while($row = mysqli_fetch_assoc($data)){ $hasil[] = $row; }
return $hasil;
}
}
function bisa($conn,$query){ $db = mysqli_query($conn,$query);
if($db){
return 1;
}else{
return 0;
}
}
function ambilsatubaris($conn,$query){ $db = mysqli_query($conn,$query); return mysqli_fetch_assoc($db); }
function hapus($where,$table,$redirect){ $query = 'DELETE FROM ' . $table . ' WHERE ' . $where; echo $query; }
?></pre><div><br>Dari Kode Diatas ↑<br>Mungkin yang salah disini :</div><pre>if($_SESSION){ if($_SESSION['role'] == 'admin'){
}else{
header('location:../index.php');
}
}else{ header('location:../index.php'); }</pre><div>Karena Variabel </div><pre>if($_SESSION)</pre><div>Tidak di definisikan.<br><br>Atau bisa jadi karena di semua function yang anda buat berhubungan ke database, tidak di tambahkan global $conn;<br><br>Contoh :<br><br></div><pre>function ambildata($conn,$query){ global $conn; $data = mysqli_query($conn,$query); if (mysqli_num_rows($data) > 0) { while($row = mysqli_fetch_assoc($data)){ $hasil[] = $row; }
return $hasil;
}
}
function bisa($conn,$query){ global $conn; $db = mysqli_query($conn,$query);
if($db){
return 1;
}else{
return 0;
}
}
function ambilsatubaris($conn,$query){ global $conn; $db = mysqli_query($conn,$query); return mysqli_fetch_assoc($db); }
function hapus($where,$table,$redirect){ global $conn; $query = 'DELETE FROM ' . $table . ' WHERE ' . $where; echo $query; }
?></pre><div><br></div><div><br></div>