-1

When this code is run this error appears Parse error: syntax error, unexpected '$_POST' (T_VARIABLE), expecting '. Im not very good at code so help is appreciated thank you.

<?php $servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

$connection = new mysqli($servername, $username, $password, $dbname);

if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);
} 


$sql = "SELECT username FROM users";
$result = $connection->query($sql);

if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
        if $_POST["username"] === $row["username"] and $_POST["password"] === $row["password"]
            header( 'Location: home.php' ); 
        }
            } else {
                echo "header( 'Location: landing.php' ) ;";
}
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

2

You forgot brackets

Replace

if $_POST["username"] === $row["username"] and $_POST["password"] === $row["password"]

with

if( $_POST["username"] === $row["username"] and $_POST["password"] === $row["password"]){
Jakob
  • 1,858
  • 2
  • 15
  • 26