简体   繁体   中英

Mysqli Query result to variable

I was trying to make a MySQL word with PHP, and I want to call the result into the next page using session. So I can put the result in the ms word file, but the value in "$_SESSION['kode_faskes'] = $d['kode_faskes'];" was stated as null .

Notice: Trying to access array offset on the value of type null in C:\\xampp\\htdocs\\test3\\index.php on line 80

this is the code

 <!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>

If you can help me then I would be grateful for this.

In addition, I'm deeply sorry about the short explanation.

The session_start() function must be the very first thing in your document. Before any HTML tags.

<?php 
session_start();
?>
<!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['cari'] = $cari;
      $_SESSION['kode_faskes'] = $d['kode_faskes'];
    }
    ?>
</table>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM