【发布时间】:2022-12-04 09:51:23
【问题描述】:
我得到一个错误 undefined array key for 'id_post',我使用这个 href 删除方法
<?php
require 'koneksi.php';
$blogs = new blog();
$no = 1;
foreach ($blogs->show() as $b) {
?>
<button type="button"><a href="proses.php?aksi=hapus&id=<?= $b['id_post'] ?>">Hapus</a></button>
<?php }; ?>
这里是 proses.php 文件
<?php
include 'koneksi.php';
$blog = new blog();
$kat = new kat();
$aksi = $_GET['aksi'];
if ($aksi == "hapus") {
$blog->hapus($_GET['id_post']);
}
这里的功能
public function hapus($id_post)
{
$connect = mysqli_connect($this->host, $this->uname, $this->pw, $this->db);
mysqli_query($connect, "DELETE FROM blog WHERE id_post='$id_post'");
}
我试过在功能上使用类似的东西但仍然没有任何改变
public function hapus($id_post)
{
$connect = mysqli_connect($this->host, $this->uname, $this->pw, $this->db);
if (isset($_GET['id_post'])) {
$id = $_GET[$id_post];
mysqli_query($connect, "DELETE FROM blog WHERE id_post='$id'");
}
}
我以前尝试过相同的代码并且可以正常工作,但现在出现了一些错误。请给我一些启示
【问题讨论】:
-
你的查询参数是
id,不是id_post