duaiwu8385 2019-04-19 18:27
浏览 48
已采纳

导航栏出现两次不尊重php if语句

I am trying to change my navigation bar depending on whether the user has signed in. Eventually also checking whether the user is an admin or not and having different list items depending on these conditions.

The issue is since my condition is in PHP it doesn't seem to respect the if statement and when the page is loaded both ul are shown.

I have a session start at the top of my page so the value of "loggedin" should be stored.

<header>
<div class="container">
    <div class="Logo">
        <img src="./images/LogoSmall.png" width="60px" height="60px" alt="Logo">
        <h2> Quality Speakers Global </h2>
    </div>
    <div>
    <nav>
    <?php
        if($_SESSION["loggedin"] == "yes"){
        ?>
        <ul>
            <li class="current"><a href="Index.html">Home</a></li>
            <li><a href="Register.html">Login/Register</a></li>
            <li><a href="Slideshow.html">Products</a></li>
            <li><a href="Report.html">Report</a></li>
            <li><a href="userpage.php">My Account</a></li>
        </ul>
    <?php } else{?>
        <ul>
            <li class="current"><a href="Index.html">Home</a></li>
            <li><a href="Register.html">Login/Register</a></li>
            <li><a href="Slideshow.html">Products</a></li>
            <li><a href="Report.html">Report</a></li>
        </ul>       
    <?php       
    }
    ?>

    </nav>
</div>
</header>

What i want is to only show the ul depending on the condition

here is my php login code:

<?php

  session_start();

  $con = mysqli_connect('localhost','root','pass1','accounts');

  if(isset($_POST["UsernameLogin"])) {

      $Logusername = $_POST['UsernameLogin']; 
  }

  if(isset($_POST["PasswordLogin"])) {

      $Logpassword = $_POST['PasswordLogin'];
  }

  $query = " select * from users where username = '$Logusername' && password = '$Logpassword'";

  $result = mysqli_query($con, $query);

  $row = mysqli_fetch_assoc($result);

  $num = mysqli_num_rows($result);

  if($num == 1) {
      $_SESSION["username"] = $Logusername;
      $_SESSION["level"] = $row["usertype"];
      $_SESSION["loggedin"] = 'yes';

      if($_SESSION["level"] == "admin") {

          header('location:AccountsPage.php');
      } else {

          header('location:userpage.php');
      }   
  } else {
    header("Location: Index.html");

  }

?>
  • 写回答

1条回答 默认 最新

  • douyakan8924 2019-04-19 18:46
    关注

    Your index.html page is not being parsed as php. Change the extension to .php or change configuration to also parse html files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败