Mysqli 查询结果到变量

我试图用 PHP 制作一个 MySQL 单词,我想使用 session 将结果调用到下一页。所以我可以把结果放在 ms word 文件中,但是里面的值"$_SESSION['kode_faskes'] = $d['kode_faskes'];"null.

注意:尝试访问第 80 行 C:\xampp\htdocs\test3\index.php 中 null 类型值的数组偏移量

这是代码

<!doctype html>

<html>

<head>

<title>Untitled Document</title>

<?php include 'connection.php'; ?>

</head>


<body>


        <form action="index.php" method="get">

        <label> Cari :</label>

        <input type="text" name="cari">

        <input type="submit" value="cari">

    </form>

    <?php

    //search norek 

    if(isset($_GET['cari']))

    {

        $cari = $_GET['cari'];

        echo "<b>Hasil Pencarian : ".$cari."</b>";

    }

    ?>

        <table width="600" border="1">

      <?php

      if(isset($_GET['cari']))

      {

          $cari = $_GET['cari'];

          $dato = mysqli_query($connect, "

SELECT

    * 

FROM

    faskes

    INNER JOIN pemilik_rekening USING ( norek )

    INNER JOIN transaksi USING ( kode_faskes )

WHERE transaksi.norek LIKE

'%".$cari."%'

");

      } else {

          $dato = mysqli_query($connect, "

SELECT

    * 

FROM

    faskes

    INNER JOIN pemilik_rekening USING ( norek )

    INNER JOIN transaksi USING ( kode_faskes )

    ");

      }

      $no = 1;

    while($d = mysqli_fetch_array($dato))

    {

      ?>

    <tr>

      <td><?php echo $no++; ?></td>

      <td><?php echo $d['kode_faskes']; ?></td>

      <td><?php echo $d['nama_faskes']; ?></td>

      <td><?php echo $d['alamat_faskes']; ?></td>

      <td><?php echo $d['norek']; ?></td>

      <td><?php echo $d['pemegang_norek']; ?></td>

      <td><?php echo $d['tanggal_bayar']; ?></td>

      <td><?php echo $d['jumlah_bayar']; ?></td>

    </tr>

    <?php }   

      session_start();

      $_SESSION['cari'] = $cari;

      $_SESSION['kode_faskes'] = $d['kode_faskes'];

    ?>

</table>

</body>

</html>

如果你能帮助我,我将不胜感激。

此外,我对简短的解释深表歉意。


桃花长相依
浏览 84回答 1
1回答

莫回无

该session_start()功能必须是文档中的第一件事。在任何 HTML 标记之前。<?php&nbsp;session_start();?><!doctype html><html><head><title>Untitled Document</title><?php include 'connection.php'; ?></head><body>&nbsp; &nbsp; &nbsp; &nbsp; <form action="index.php" method="get">&nbsp; &nbsp; &nbsp; &nbsp; <label> Cari :</label>&nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name="cari">&nbsp; &nbsp; &nbsp; &nbsp; <input type="submit" value="cari">&nbsp; &nbsp; </form>&nbsp; &nbsp; <?php&nbsp; &nbsp; //search norek&nbsp;&nbsp; &nbsp; if(isset($_GET['cari']))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $cari = $_GET['cari'];&nbsp; &nbsp; &nbsp; &nbsp; echo "<b>Hasil Pencarian : ".$cari."</b>";&nbsp; &nbsp; }&nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; <table width="600" border="1">&nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; if(isset($_GET['cari']))&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $cari = $_GET['cari'];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $dato = mysqli_query($connect, "SELECT&nbsp; &nbsp; *&nbsp;FROM&nbsp; &nbsp; faskes&nbsp; &nbsp; INNER JOIN pemilik_rekening USING ( norek )&nbsp; &nbsp; INNER JOIN transaksi USING ( kode_faskes )WHERE transaksi.norek LIKE'%".$cari."%'");&nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $dato = mysqli_query($connect, "SELECT&nbsp; &nbsp; *&nbsp;FROM&nbsp; &nbsp; faskes&nbsp; &nbsp; INNER JOIN pemilik_rekening USING ( norek )&nbsp; &nbsp; INNER JOIN transaksi USING ( kode_faskes )&nbsp; &nbsp; ");&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; $no = 1;&nbsp; &nbsp; while($d = mysqli_fetch_array($dato))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td><?php echo $no++; ?></td>&nbsp; &nbsp; &nbsp; <td><?php echo $d['kode_faskes']; ?></td>&nbsp; &nbsp; &nbsp; <td><?php echo $d['nama_faskes']; ?></td>&nbsp; &nbsp; &nbsp; <td><?php echo $d['alamat_faskes']; ?></td>&nbsp; &nbsp; &nbsp; <td><?php echo $d['norek']; ?></td>&nbsp; &nbsp; &nbsp; <td><?php echo $d['pemegang_norek']; ?></td>&nbsp; &nbsp; &nbsp; <td><?php echo $d['tanggal_bayar']; ?></td>&nbsp; &nbsp; &nbsp; <td><?php echo $d['jumlah_bayar']; ?></td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; $_SESSION['cari'] = $cari;&nbsp; &nbsp; &nbsp; $_SESSION['kode_faskes'] = $d['kode_faskes'];&nbsp; &nbsp; }&nbsp; &nbsp; ?></table></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP