Syntax error php

Asked

Viewed 457 times

1

I downloaded a simple help desk system, but this returning me the following error after login:

 Parse error: syntax error, unexpected '}' in C:\wamp\www\helpdesk\login.php on line 48

login.php

<?
include "config.php";
$date = date("d/m/y");
$hora = date("H:i");

@session_start(); 

if (!mysql_connect($Host, $Usuario, $Senha)) {
    echo mysql_error();
    exit();
}
mysql_select_db($Base);

$user = $HTTP_POST_VARS["username"];
$pwd  = $HTTP_POST_VARS["senha"];

$sQuery = "select cod_usuario, nom_usuario, login, pwd_usuario, nivel
           from   usuarios
           where  login = '" . $user . "'";
$oUser = mysql_query($sQuery)
         or die("Query invalida: " . mysql_error());

$row = mysql_fetch_object($oUser);
if ($num_rows = mysql_num_rows($oUser) == 1) {
    if ($row->pwd_usuario == $pwd) {
        if ($row->nivel == $Nivel) {
           $_SESSION["log_usuario"] = $user;
           $_SESSION["pwd_usuario"] = $pwd;
           $_SESSION["nom_usuario"] = $row->nom_usuario;
           $_SESSION["cod_usuario"] = $row->cod_usuario;

           $sQuery1 = "insert into acesso (cod_user, nome_user, data, hora)
             values ('" . $row->cod_usuario . "',
                     '" . $user . "',
                     '" . $date . "',
                     '" . $hora  . "')";
           mysql_query($sQuery1);
           echo "<script>window.location='index_2.php'</script>";
        } else {
               ?>
               <script language="JavaScript">
               <!--
               alert("Nivel acesso incorreto!");
               window.location = '"index.php';
               //-->
               </script>
            <?php
            } //linha do erro
    } else {
        ?>
            <script language="JavaScript">
            <!--
            alert("Senha incorreta!");
            window.location = 'index.php';
            //-->
            </script>
        <?php
    }
} else {
    ?>
        <script language="JavaScript">
        <!--
        alert("Usuário não encontrado!");
        window.location = 'index.php';
        //-->
        </script>
    <?php
}
?>
  • Do not use this system, it is not good, play it out, it uses features removed from php. If you can highlight which line of error helps a lot.

  • Yeah, I tried a bunch of amendments, and I actually thought the problem was he was really old.

  • This code is totally obsolete.

  • What is line 48?

  • @session_start(); how sad to see that :(

  • It doesn’t solve, I’ve seen and reviewed these keys.

  • The problem is the 42 where you open a <!-- and on line 45 is commented the closing //-->

  • @Jorgeb. the problem is the same or is the answer below?

  • @Math is one of the problems. But in this case it is not the cause of the error.

Show 5 more comments

1 answer

6


Obsolete PHP code, but answering your question.

At the beginning of the code you have <? swap for <?php.

This is because all your remaining openings are utilizing <?php.

Try it, put it all <?php. Using both in the same code will give the error, which may lead to some misconceptions.

Your problem, though it may seem, has nothing to do with missing braces.

That’s enough to make the mistake Parse error: syntax error, Unexpected '}'

See your "config.php" file if you don’t have the same problem, as you are doing a include, the error can be inherited.

If you have access to server settings, check your php.ini, look for the line short_open_tag and switch to "on". Restart the apache service.

After setting up, there will be no problem using short tags.

  • @Diegofelipe is simple, do like me, have a testing environment and take the test! Simple!

  • It’s true, the mistake syntax was because of the <?

  • Because it is online, there may be a parse before php actually interprets it, but it works smoothly to mix tags: http://sandbox.onlinephpfunctions.com/code/bbdc29bd7c29eebd9a9c480c2817bcf3bc38e0ab

  • @Luishenrique yes but not in this code. Error occurs due to lack of '<? php' at first.

  • 2

    @Luishenrique on my server does not work the code you posted above. It is probably some configuration on the/php server. I just don’t understand so many negatives for an answer that’s plausible.

  • @Filipemoraes You’re right you’re with short_open_tag = on in php.ini? For example, only <?= "hello world" ?> works on your server?

  • @Luishenrique yes it works. Note that the server you used can replace the tags to avoid these kinds of problems.

  • Guys I tested in netbeans, and it accuses the same OP syntax error, when fixing the php tag, the error goes away. It was my mistake to read the same code.

  • I reversed the downvote, but it is very strange this, I had never seen this problem. I tested it on my Amazon server here and it also worked my example. And I couldn’t find anything related to that by doing a quick search.

  • @Luishenrique you’re absolutely right, had the "short_open_tag" off, when changing to "on" the problem no longer arises. Was complementary to the answer.

  • @Filipemoraes you could complement the answer with this information, just not to leave room for other misinterpretations.

  • 1

    @Diegofelipe completed the question.

Show 7 more comments

Browser other questions tagged

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