这段代码应该显示三个按钮:修改项目、添加项目和查看帐户,只有在显示了用户名和密码(硬编码的username = frankbutt和password=franbuttpower123)的正确凭据后,才应该显示这些按钮。
代码:
<?php
$show = False;
if(strcmp($_POST["username"], "FrankButt") ==0){
if(strcmp($_POST["password"], "frantbuttpower123") ==0){
$show = True;
}
}
?>
<html>
<link rel="stylesheet" href="../style/admin.css">
<link rel="stylesheet" href="../style/form.css">
<h1 class="adminHeader">Admin Access</h1>
<br>
<br>
<br>
<form action="adminLogin.php" method="post" class="formBox">
<input type="text" name="username" class="loginFill" placeholder="Username"><br>
<input type="password" name="password" class="loginFill" placeholder="Password"><br>
<button type="submit" class="adminsubmitsignin">Sign In</button>
</form>
if(<?php echo $show; ?>){
<button class= "adminOptions" onClick="selectItem.php">Modify Items</button>
<br>
<button class="adminOptions" onClick="adminImageUpload.php">Add Items</button>
<br>
<button class="adminOptions" onClick="adminHome.php">View Accounts</button>
<br>
}
</html>
我试图通过创建一个布尔值来解决这个问题,如果用户名和密码条目等于给定的硬编码值,则该布尔值为真。然后我想用这个布尔值让html代码以某种方式运行
可以在html
中使用if的简写形式<form action="adminLogin.php" method="post" class="formBox">
<input type="text" name="username" class="loginFill" placeholder="Username"><br>
<input type="password" name="password" class="loginFill" placeholder="Password"><br>
<button type="submit" class="adminsubmitsignin">Sign In</button>
</form>
<?php if ($show): ?>
<button class= "adminOptions" onClick="selectItem.php">Modify Items</button>
<br>
<button class="adminOptions" onClick="adminImageUpload.php">Add Items</button>
<br>
<button class="adminOptions" onClick="adminHome.php">View Accounts</button>
<br>
<?php endif;?>