Jump to content

[SOLVED] unexpected ; (impossable?)


freddyw

Recommended Posts

Im really not sure why I'm recieving this error.

 

heres the code im working on

 

<?      $username = (isset($_POST['username']) ? pg_escape_string($_POST['username']) : "";
        $password = (isset($_POST['password']) ? pg_escape_string($_POST['password']) : "";
        $referer = (isset($_SERVER['HTTP_REFERER']) ? 
        $_SERVER['HTTP_REFERER'] : "noreferer";
        
        #this will make user return to login page if a field is left empty
            if ( ( !$username ) or (!$password) )
                {
                header ( "location:$referer" );
                exit();
                }
        
                
                $conn = @pg_connect("connection details hidden");
                
                $psql="select * from users where username =\"$username\" and password = password (\"$password\")";
                
                $rs = @pg_query ($psql,$conn)
                    or die ("could not execute query");
                    
            #get number of rows that match username and password
                $num = pg_num_rows($rs);
            
            #if there is a match log in successful
            if ( $num !=0 )
                {
                $msg = "Welcome $username - You are logged in";
                }
            else #return to log in page
                {
                header ( "location:$referer" );
                exit();
                }
        
?>

<html>
    <head><title>You are logged in</title></head>
        <body>
            <? echo ( $msg );
            ?>
        </body>
<html>        

 

any ideas why im recieving the error. I checked the whole code and cant see a ; out of place anywhere.

 

 

EDIT: i changed the short tag to <?php

the html is now shoing up with the log in from. however once the details are entered, it switched to the php page and is just blank

Link to comment
https://forums.phpfreaks.com/topic/166511-solved-unexpected-impossable/
Share on other sites

Haha, thanks.

 

just to confirm. Should it be...

<?      $username = (isset($_POST['username'])) ? pg_escape_string($_POST['username']) : "";
        $password = (isset($_POST['password'])) ? pg_escape_string($_POST['password']) : "";
        $referer = (isset($_SERVER['HTTP_REFERER'])) 

 

I think im right with the first 2 lines.

Just the referer line im unsure of.

Thanks. Thats cleared up the blank page.

Sorry if I'm being a a pain but im now recieving this error.

 

Parse error: syntax error, unexpected T_VARIABLE in /home2/webusers/07/344740/public_html/sporticket/login.php on line 4

 

<?php      $username = (isset($_POST['username'])) ? pg_escape_string($_POST['username']) : "";
        $password = (isset($_POST['password'])) ? pg_escape_string($_POST['password']) : "";
        $referer = (isset($_SERVER['HTTP_REFERER'])) 
        $_SERVER['HTTP_REFERER'] : "noreferer";
        
        #this will make user return to login page if a field is left empty
            if ( ( !$username ) or (!$password) )
                {
                header ( "location:$referer" );
                exit();
                }

 

Id appreciate your help

You have this statement:

$referer = (isset($_SERVER['HTTP_REFERER'])) $_SERVER['HTTP_REFERER'] : "noreferer";

 

That should be:

$referer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "noreferer";

 

Note that statements are only terminated by ; or ?>. Going to a new line doesn't mean it's a new statement.

 

I would recommend reading Language Reference in the manual.

I would love to click the solve to this topic. I thought u helped me to that point Daniel.

 

I appreciate yor help so far. I'm greatful for it.

 

The script is working, However im recieving "could not ececute query."

 

I made a change to my original script, and still recieve the error. I changed line 15 to read

$psql="select * from users where username =\"$username\" and password =\"$password\"";

 

rather than

$psql="select * from users where username =\"$username\" and password = password (\"$password\")";

 

and it still wont execute. Is this something obvious that I'm missing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.