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;

}

?>

avatar Y04Y
@Y04Y

5 Kontribusi 2 Poin

Diperbarui 3 tahun yang lalu

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>&lt;?php session_start();

if($_SESSION){ if($_SESSION['role'] == 'admin'){

}else{
    header(&#039;location:../index.php&#039;);
}

}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) &gt; 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; }

?&gt;</pre><div><br>Dari Kode Diatas ↑<br>Mungkin yang salah disini :</div><pre>if($_SESSION){ if($_SESSION['role'] == 'admin'){

}else{
    header(&#039;location:../index.php&#039;);
}

}else{ header('location:../index.php'); }</pre><div>Karena Variabel&nbsp;</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) &gt; 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; }

?&gt;</pre><div><br></div><div><br></div>

avatar X451
@X451

41 Kontribusi 30 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban