0

This code is supposed to reveal three buttons: modify items, add items, and view accounts, which should only be shown once proper credentials for username and password (hardcoded username = frankbutt and password=franbuttpower123) are shown.

Code:

<?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>

I tried to approach the problem by making a boolean that becomes true if the username and password entries are equal to the hardcoded values given. I then wanted to use that boolean for the html code to behave a certain way

1
  • Your if is inside the HTML, which doesn't know anything about if statements. Move the PHP tags to surround the full if statement and opening brace, and add another set to surround the closing brace Commented Dec 1, 2022 at 16:26

1 Answer 1

1

you can use short form of if in html

<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;?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.