我想制作个人用户可以编辑和删除帖子的博客系统,但这不起作用,每个用户都可以编辑删除任何用户帖子。我从user_table获得用户名并匹配新闻源表然后创建一个条件,但它不起作用。那么我该如何解决这个问题
<?php
///Data display post
$display_latest_news = mysqli_query($con,"SELECT * FROM `newsfeeds` ORDER BY `news_id` DESC");
while($row = mysqli_fetch_array($display_latest_news))
{
$news_id = $row['news_id'];
$news_post= $row['news_post'];
$news_image = $row['news_image'];
$news_department= $row['news_department'];
$news_date = $row['news_date'];
$news_time= $row['news_time'];
$username = $row['username'];
$user_id= $row['user_id'];
?>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title media">
<div class="media-left">
<img class="avator" src="images/mypic.jpg" alt="profile picture" />
</div>
<div class="media-body">
<a href="#"> <?php echo $username; ?> </a>
<p> 2 Mins </p>
</div>
<div class="media-right">
<?php
$username_collect = mysqli_query($con,"SELECT `username` FROM `newsfeeds` WHERE `username`='$username'");
while($check_usename = mysqli_fetch_array($username_collect))
$username_url = $check_usename['username'];
//var_dump($username_url);
//exit();
{
if ($username_url) {
?>
<a class="btn btn-default" href="postedit.php?p_id=<?php echo $news_id;?>"><span class="glyphicon glyphicon-edit"> </span></a>
<a onclick="return DELETE();" class="btn btn-default" href="postdelete.php?p_id=<?php echo $news_id;?>"><span class="glyphicon glyphicon-remove"> </span></a>
<?php
}
else
{
?>
<a class="btn btn-default" disabled="disabled" href="postedit.php?p_id=<?php echo $news_id;?>"><span class="glyphicon glyphicon-edit"> </span></a>
<a onclick="return DELETE();" class="btn btn-default" disabled="disabled" href="postdelete.php?p_id=<?php echo $news_id;?>"><span class="glyphicon glyphicon-remove"> </span></a>
<?php
}
}
//var_dump($username);
//exit();
?>
答案 0 :(得分:0)
如果您在发布数据中有user_id,则表示您正在从会话或Cookie中保存该ID,因此,假设您需要将 user_id from session 或Cookie与匹配来自帖子数据的user_id
像
这样的东西// make sure your pinch zoom is enabled
webView.getSettings().setBuiltInZoomControls(true);
// don't show the zoom controls
webView.getSettings().setDisplayZoomControls(false);
希望它能解决你的问题!
答案 1 :(得分:0)
首先,我希望在您的新/文章表中插入发布该文章的用户的ID。
基于此,您可以查询该特定用户发布的所有新闻/文章。
$ sql =“从新闻中选择*,其中user = $ user”;
其中$ user是您的用户的session_id
希望这可以解决问题