PHP error, 'Exit' (T_EXIT)

Asked

Viewed 257 times

0

I’m practicing a little php, and when I run it, this error appears on the screen of the host:

Parse error: syntax error, Unexpected 'Exit' (T_EXIT), expecting ',' or ';' in C: xampp htdocs login.php on line 22

i understand what is syntax error, however, I would like to understand the error.

[
<?php

$host = "localhost";
$user = "root";
$pass = "";
$db = "users";

mysql_connect($host, $user, $pass);
mysql_select_db($db);

if (isset($_POST['username'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];

    $sql = "SELECT * FROM user WHERE username='".$username."'AND password='".$password."'LIMIT 1";
    $res = mysql_query($sql);
    if (mysql_num_rows($res) == 1) {
    echo "logado";
    exit();
    } else {
    echo "dados incorretos"
        exit();
    }
    }

?>
]
  • Looks like we missed one ; in the echo before the exit();, } else {&#xA; echo "dados incorretos" you are using some IDE?

  • Yes, I am using an IDE, Brackets, although not yet suitable for server side, is only for testing even.

1 answer

6

Error says the function exit() was not expected but a ; or the error is in the line before the exit().

} else {
   echo "dados incorretos" <---- cade o ponto e virgula ?
exit();

To avoid this type of error use an IDE like eclipse or text editors with advanced functionality such as Notepad++ or sublimetext.

  • yeah, they told me that the eclipse is well recommended. but for now I’m using the current one for same training.

  • 5

    It has nothing to do with the IDE, but the syntax error of the comma.. +1

  • 2

    Silvio, the point is that using an IDE prevents the error, since it reports the error, and defines correction methods.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.