简体   繁体   English

为什么我尝试删除帖子时出现此错误?

[英]Why am i getting this error when i try to delete a post?

for school i have to make a online portfolio with a cms. 为了上学,我必须使用cms制作在线投资组合。 for the most part it is going well, but when i try to add a delete function, so a admin can delete a post i get a error from google chrome: Notice: Undefined variable: id in C:\\xampp\\htdocs\\portfoliojbehrens\\admin\\delete.php on line 4. the code : 在大多数情况下,它运行良好,但是当我尝试添加删除功能时,管理员可以删除帖子,我从google chrome浏览器收到错误:注意:未定义的变量:C:\\ xampp \\ htdocs \\ portfoliojbehrens \\中的id第4行的admin \\ delete.php代码:

delete.php: delete.php:

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

and the functions page of this: 以及功能页面:

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");
}

i hope u can help me with this 我希望你能帮助我

It looks like deletePost() just sets a header to the posts.php page. 看起来deletePost()只是将标题设置为posts.php页面。 You're trying to access $id which is never defined. 您正在尝试访问从未定义的$id

Update delete.php as follows: 更新delete.php如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试通过脚本传递POST变量时,为什么没有收到响应? - Why am I not getting a response when I try to pass POST vars via script? 尝试启动连接时为什么会出现NULL? - Why am I getting NULL when I try to initiate a connection? 尝试打开Materialize Modal时为什么会出现此错误? - Why am I getting this error when I try to open Materialize Modal? 当我尝试在 Invoice 表上添加外键时,为什么会出现此错误? - Why am i getting this error when i try to add foreign keys on Invoice table? 为什么我在尝试运行 cron 作业时收到 mysql 扩展错误? - Why am I getting mysql extension error when I try to run a cron job? 从Angular2应用发布到PHP时为什么会出现404错误? - Why am I getting a 404 error when I post from an Angular2 app to PHP? 当我尝试将PHP应用程序部署到Google App Engine时,为什么突然出现400错误? - When I try to deploy my PHP application to Google App Engine, why am I suddenly getting a 400 error? 为什么当var_dump($ _ POST)显示数组时出现未定义的索引错误? - Why Am I Getting an Undefined Index Error When var_dump($_POST) Shows an Array? 使用axios发出发布请求时,为什么会出现500服务器错误? - Why am I getting 500 server error when making post request with axios? 为什么会出现此错误 - Why am I getting this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM