【问题标题】:Why am i getting this error when i try to delete a post?为什么我在尝试删除帖子时收到此错误?
【发布时间】:2014-01-12 19:41:12
【问题描述】:

对于学校,我必须使用 cms 制作在线作品集。在大多数情况下它进展顺利,但是当我尝试添加删除功能时,管理员可以删除帖子我从谷歌浏览器收到错误:注意:未定义的变量:C:\xampp\htdocs\portfoliojbehrens\ 中的 id第 4 行的 admin\delete.php。 代码:

删除.php:

 <?php
include_once("../includes/functions.php");
sec_session_start();
  deletePost($mysqli, $id).($_GET['id']);
?>

以及这个的功能页面:

function getAdminPosts($mysqli)
{
    $query = "SELECT * FROM posts";
    $post = array();

    if ($result = mysqli_query($mysqli, $query)) {
        while ($row = mysqli_fetch_assoc($result)) {
            $post[] = $row;
            echo "<tr><td>".$row['title']."</td><td>".$row['author']."</td><td><a href=\"delete.php?id=".$row['id']."\">Delete</a><br /><a href=\"edit.php?id=".$row['id']. "\">Edit</a></td></tr>";
        }
    }
}
function deletePost($mysqli, $id){
    $id = (int) $id;
    $query = "DELETE FROM posts WHERE ID = $id";
    mysqli_query($mysqli, $query);
    return true;
    header("Location: ../admin/posts.php");
}

我希望你能帮我解决这个问题

【问题讨论】:

  • 首先,deletePost()后面的.是什么?
  • 我尝试从 url 获取 id。但看到你的帖子,我想这不是正确的做法。 @BenM

标签: php mysqli sql-delete


【解决方案1】:

看起来deletePost() 只是为posts.php 页面设置了一个标题。您正在尝试访问从未定义的 $id

更新delete.php如下:

include_once("../includes/functions.php");
sec_session_start();
deletePost($mysqli, $_GET['id']);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-21
  • 1970-01-01
  • 1970-01-01
  • 2021-06-17
  • 2016-07-12
  • 2012-05-16
  • 1970-01-01
相关资源
最近更新 更多