我一直在开发一个php脚本,可以从我的博客中删除文章。但现在,每个人都可以删除每个人的帖子,如果他们登录。我想限制这对作者的帖子,所以他们只能删除自己的帖子。我怎样才能做到这一点?
我的index.php是这样的:
<script language ="JavaScript" type="text/javascript">
function delpost(id, title) {
if (confirm("Are you sure you want to delete '" + title + "'")) {
window.location.href = 'index.php?delpost=' + id;
}
}
</script>
<?php
try {
$author = $_SESSION['author'];
$stmt = $db->query('SELECT postID, postTitle,postAlttext, postDesc, postDate, postAlttext, postImage, author FROM blog_posts ORDER BY postID DESC');
while ($row = $stmt->fetch()) {
echo '<span style="float: right"><a href="edit-post.php?id='.$row['postID'].'"><i class="material-icons" style="font-size:36px;color:black">border_color</i></a></span>';?>
<a href="javascript:delpost('<?php echo $row['postID'];?>','<?php echo $row['postTitle'];?>')"><i class="material-icons" style="font-size:36px;color:red">delete</i></a>
暂无答案!
目前还没有任何答案,快来回答吧!