views:

71

answers:

4

EDIT: I forgot to add semi colons. Now there is another problems. I'm getting a error:

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\useraccess.php on line 12

It outputs:

0){ echo 'si'; } ?> 

When it should only output 'si' in the body.

Here's the code:

<html>
    <head>
    </head>

    <body>
        <? 
            $user = mysql_real_escape_string($_GET["u"])
            $pass = mysql_real_escape_string($_GET["p"])

            $query = "SELECT * FROM usario WHERE username = '$user' AND password = '$pass'"

            mysql_connect(localhost, "sergio", "123");
            @mysql_select_db("multas") or die( "Unable to select database");

            $result=mysql_query($query);
            if(mysql_numrows($result) > 0){
                echo 'si';
            }   
         ?>
    </body>
</html>
+5  A: 

That is because you are using short php tags <? that most likely are not enabled in php.ini. Try using <?php or enable short tags from php.ini but this is not recommended.

Also note that you are missing semi-colon (;) fot these lines:

$user = mysql_real_escape_string($_GET["u"])
$pass = mysql_real_escape_string($_GET["p"])

$query = "SELECT * FROM usario WHERE username = '$user' AND password = '$pass'"
Sarfraz
The name of the option to enable short tags is:'short_open_tag'.Take a look at this article to see why enabling this is not recommended: http://terrychay.com/article/short_open_tag.shtml
matias
@matias: Thanks for adding that link.
Sarfraz
+2  A: 

You need semicolons on your $user, $pass, and $query variables.

Robert
+2  A: 

Missing semi-colon after

 $query = "SELECT * FROM usario WHERE username = '$user' AND password = '$pass'" 

Stick quotes around 'localhost'

Mark Baker
+3  A: 

Regarding the "Unexpected T String" error:

The mysql connect statement should read:

 mysql_connect('localhost', 'sergio', '123');
Satanicpuppy
Why should it have single quotes?
Serg
@sergia tapia: It's a little better for memory management: in php, if you use double quotes, the string is parsed looking for variables.
Satanicpuppy