-3

So I've got a very simple html page which uses a post php method to send the username and password to the php script. However I get the error: unexpected '&&' (T_BOOLEAN_AND) when the details are passed to the script. Any ideas why?

Here's the html form:

<form action="login.php" method="post">
    <p> Username: </p>
    <input type="text" name="username"/>
    <p> Password: </p>
    <input type="text" name="password"/>
    <input type="submit" value="Submit"/>
</form>

And here is the login.php script:

 <?php
    if ($_POST["username"] == "t5" ) &&
        ($_POST["password"] == "just4fun") {    
        session_start();
        $_SESSION[‘username’] = true;
        header('Location  menu.php');
    }
    else { header('Location loginform.html') }
?>

Thanks in advance.

JL9
  • 533
  • 3
  • 17

2 Answers2

2

This should work, also notice how I changed the == to ===. This is good practive when checking a string.

You were missing a ; after the else statement and the && needs to go inside of the if(condition && condition)

if ($_POST["username"] === "t5" && $_POST["password"] === "just4fun") 
    {    
         session_start();
         $_SESSION['username'] = true;
         header('Location: menu.php');
    } else {
         header('Location: loginform.html');
    }
Andrew Rayner
  • 1,056
  • 1
  • 6
  • 20
0

The && sign for your if statement goes inside the parentheses and there should only be one set of parentheses.

if ($_POST["username"] == "t5" && $_POST["password"] == "just4fun")

Also [‘username’] should have quotes ['username']

Location should be followed with colons too.

Wowsk
  • 3,637
  • 2
  • 18
  • 29