masalah Stack trace

Hallo teman2 saay mau tanya ni, saya ada masalah saat tampil table. notif nya : Fatal error: Uncaught Error: mysqli object is already closed in C:\xampp\htdocs\perpustakaan\tes.php:14 Stack trace: #0 C:\xampp\htdocs\perpustakaan\tes.php(14): mysqli_query(Object(mysqli), 'SELECT * FROM t...') #1 {main} thrown in C:\xampp\htdocs\perpustakaan\tes.php on line 14
boleh sarannya teman2?

table
<?php include 'koneksi/connection.php'; ?>
<!-- table -->
<table border="2" class="table table-striped" style="width:100%">
        <thead>
            <tr>
                <th>NO.</th>
                <th>TANGGAL</th>
                <th>NAMA BUKU</th>
                <th>KETERANGAN</th>
            </tr>
        </thead>
        <?php 
        $no=1;
        $ambildata = mysqli_query($con, "SELECT * FROM tb_perpustakaan");
        while ($tampil = mysqli_fetch_array($ambildata)){
            echo "
            <tr>
                <td>$no</td>
                <td>$tampil[tanggal]</td>
                <td>$tampil[nama_buku]</td>
                <td>$tampil[keterangan]</td>
            </tr>
            ";

            $no++;
            
        }
        ?>
        </tbody>
    </table>


koneksi
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$dbname = 'db_perpustakaan';

$con = mysqli_connect($host,$user,$pass);
mysqli_close($con);

// if ($dbselect == true) {
//     echo "Connection Success!";
// } else {
//     echo "Connection Failed!";
// }
avatar novaje

@novaje

27 Kontribusi 3 Poin


Jawaban

Itu kamu baru membuka koneksi.

$con = mysqli_connect($host,$user,$pass);
tapi kenapa langsung di matikan kembali
mysqli_close($con);
 
avatar GrennKren

@GrennKren

61 Kontribusi 45 Poin

  • jadi solusi nya gmn bg? di hapus mysqli close nya? - @novaje
  • ya hapus aja itu - @GrennKren
  • di tampilan table nya bg muncul ini : Fatal error: Uncaught mysqli_sql_exception: No database selected in C:\xampp\htdocs\perpustakaan\tes.php:14 Stack trace: #0 C:\xampp\htdocs\perpustakaan\tes.php(14): mysqli_query(Object(mysqli), 'SELECT * FROM t...') #1 {main} thrown in C:\xampp\htdocs\perpustakaan\tes.php on line 14 - @novaje

Tampikan semua |


Login untuk gabung berdiskusi