您好我正在创建一个基于用户级别的导航系统。我制作的代码没有显示任何错误,但没有显示菜单。我不知道我哪里出错了。我用谷歌搜索了这种菜单,但找不到任何解决方案。谁能对我犯的错误进行排序?或者告诉我是否有其他方法可以做到这一点?
这是我的代码。
<html>
<head>
<title>Index</title>
</head>
<body>
<!--database connection-->
<?php
//error_reporting(0);
'session_start()';
$con = new mysqli('localhost', 'username', 'password', 'database');
if($con->connect_errno > 0){
die('Sorry, We\'re experiencing some connection problems.');
}
?>
<!--functions-->
<?php
function loggedin(){
if(isset($_SESSION['user_id'])){
return true;
}else{
return false;
}
}
?>
<!--titlebar-->
<div>
<?php
if(loggedin()){
$my_id=$_SESSION['user_id'];
$log=$con->prepare("SELECT username,user_level FROM users WHERE user_id='$my_id'");
$log->execute;
$log->bind_result($username, $user_level,$my_id);
$log->store_result;
if($log->fetch()) //fetching the contents of the row
{
if($user_level=='a'){?>
<a href = 'index.php'>Home</a>
<a href = 'admin.php'>Admin</a>
<a href = 'index.php'>Log Out</a>
<?php
}if($user_level=='m'){?>
<a href = 'index.php'>Home</a>
<a href = 'profile.php'>Profile</a>
<a href = 'index.php'>Log Out</a>
<?php
}else{?>
<a href = 'index.php'>Home</a>
<a href = 'login.php'>Login</a>
<a href = 'register.php'>Register</a>
<?php
}
}
}
?>
</div>
Index
</body>
</html>
我对我的登录页面使用了相同的方法,效果很好。这是我的登录页面代码。
<html>
<head>
<title>LOGIN</title>
</head>
<body>
<?php include 'connect.php';?>
<?php include 'functions.php';?>
<?php include 'titlebar.php';?>
<h3>LOGIN HERE:</h3>
<form action ="" method="post">
User Name:<br/>
<input type='text' name='username' />
<br/><br/>
Password:<br/>
<input type='password' name='password' />
<br/><br/>
<input type='submit' name='submit' value='login'>
</form>
<?php
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
$stmt = $con->prepare("SELECT user_id, username, password, status FROM users WHERE username=? AND password=? LIMIT 1");
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
$stmt->bind_result($user_id, $username, $password, $status);
$stmt->store_result();
if($stmt->num_rows == 1) //To check if the row exists
{
if($stmt->fetch()) //fetching the contents of the row
{
if ($status == 'd') {
echo "YOUR account has been DEACTIVATED.";
exit();
}
if ($status == 'b') {
echo "YOUR account has been BANNED.";
exit();
}
if ($status == 'n') {
echo "YOUR account has NOT YET BEEN ACTIVATED.";
exit();
}
else {
$_SESSION['Logged'] = 1;
$_SESSION['user_id'] = $user_id;
$_SESSION['username'] = $username;
echo 'Success!';
exit();
}
}
}
else {
echo "INVALID USERNAME/PASSWORD Combination!";
}
$stmt->close();
}
else
{
}
$con->close();
?>
</body>
</html>
任何帮助将不胜感激。
谢谢你。