我正在创建一个网站,我遇到了一个问题,在搜索了一段时间后,我发现很难在网上找到解决方案。
所以我的网站是使用bootstrap框架制作的,有许多页面可以显示数据库中的记录,然后编辑或删除,并将新记录添加到数据库中。现在我显然不想让任何人来我的网站上删除或编辑我的任何记录,这就是为什么我创建了一个登录和注册系统,它工作得很好。
但问题是,在用户登录之前,我如何对用户隐藏添加、编辑和删除按钮?或者我必须创建另一个页面来显示数据?
例如,我的新闻页面包含以下文件: config.php;index.php;add_news.php;edit_news;delete_news.php;read_more.php。现在我想对未登录的用户隐藏add_news.php、edit_news.php和delete_news.php。我真的卡住了,请帮帮忙。
<!-- Page Content -->
<?php
// load the configuration file.
include("config.php");
//load news from the database and then ORDER them by newsid
//you will notice that newlly added news will appeare first.
//also you can OREDER by (dtime) instaed of (news id)
$result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
//lets make a loop and get all news from the database
while($myrow = mysql_fetch_array($result))
{//begin of loop
//now print the results:
echo "<b>Title: ";
echo $myrow['title'];
echo "</b><br>On: <i>";
echo $myrow['dtime'];
echo "</i><hr align=left width=160>";
echo $myrow['text1'];
// Now print the options to (Read ,Edit or Delete the news article)
echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
if(isset($_SESSION['userid'])) {
<div>
|| <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a>
|| <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";
</div>
}//end of loop
?>发布于 2016-05-22 21:07:46
试一试
<?php
// load the configuration file.
include("config.php");
//load news from the database and then ORDER them by newsid
//you will notice that newlly added news will appeare first.
//also you can OREDER by (dtime) instaed of (news id)
$result = mysql_query("SELECT * FROM news ORDER BY newsid DESC",$connect);
//lets make a loop and get all news from the database
while($myrow = mysql_fetch_array($result))
{//begin of loop
//now print the results:
echo "<b>Title: ";
echo $myrow['title'];
echo "</b><br>On: <i>";
echo $myrow['dtime'];
echo "</i><hr align=left width=160>";
echo $myrow['text1'];
// Now print the options to (Read ,Edit or Delete the news article)
if(isset($_SESSION['user_id'])){
echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
|| <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a>
|| <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";
}//if session
}//end of loop
?>https://stackoverflow.com/questions/37373909
复制相似问题