[英]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.