-2

I didn't have any code here on line 31 in this code so what do you think what's the problem here? :)

<?php

require('config.php');

if(isset($_POST['submit'])) {

$uname = mysqli_real_escape_string($con, $_POST['uname']);
$pass = mysqli_real_escape_string($con, $_POST['pass']);

$sql = mysqli_query($con, "SELECT * FROM users WHERE uname = '$uname' AND pass = '$pass'");
if (mysqli_num_rows($sql) > 0) {
  echo "You are now logged in.";
  exit();
}

} else {

  $form = <<<EOT
  <form action="login.php" method="POST">
  Username: <input type="text" name="uname" /></br>
  Password: <input type="password" name="pass" /></br>
  <input type="submit" name="submit" value="Log in" />
  </form>
  EOT;
  echo $form;
}



?>

I think that all my brackets are fine :D

Amar Muratović
  • 451
  • 2
  • 5
  • 11
  • 1
    Remove the bracket `}` – Daan Jan 06 '16 at 15:13
  • Which one did you remove ? @AmarMuratović – Daan Jan 06 '16 at 15:16
  • in if statement and I also try last one – Amar Muratović Jan 06 '16 at 15:16
  • Is `EOT` indented? `That means especially that the identifier may not be indented` http://php.net/manual/en/language.types.string.php... `If this rule is broken and the closing identifier is not "clean", it will not be considered a closing identifier, and PHP will continue looking for one. If a proper closing identifier is not found before the end of the current file, a parse error will result at the last line.` – chris85 Jan 06 '16 at 15:18

2 Answers2

1

The EOT token must be at column 1 in your editor.

<?php

require('config.php');

if(isset($_POST['submit'])) {

  $uname = mysqli_real_escape_string($con, $_POST['uname']);
  $pass = mysqli_real_escape_string($con, $_POST['pass']);

  $sql = mysqli_query($con, "SELECT * FROM users WHERE uname = '$uname' AND pass = '$pass'");
if (mysqli_num_rows($sql) > 0) {
  echo "You are now logged in.";
  exit();
}

} else {

  $form = <<<EOT
  <form action="login.php" method="POST">
  Username: <input type="text" name="uname" /></br>
  Password: <input type="password" name="pass" /></br>
  <input type="submit" name="submit" value="Log in" />
  </form>
EOT;
  echo $form;
}
?>
maxhb
  • 8,554
  • 9
  • 29
  • 53
1

The end of the $form string cannot be found, from http://php.net/manual/en/language.types.string.php:

The closing identifier must begin in the first column of the line.

So you'll have to move EOT; to the very beginning of the line.

} else {

  $form = <<<EOT
  <form action="login.php" method="POST">
  Username: <input type="text" name="uname" /></br>
  Password: <input type="password" name="pass" /></br>
  <input type="submit" name="submit" value="Log in" />
  </form>
EOT;
  echo $form;
}
Goujon
  • 187
  • 5