Jump to content

Can't execute query


freddyw

Recommended Posts

Can anybody see why the query isnt executing. I cant see the problem. Im new to PHP im using PHP5 and not mysql.

 

any ideas?

 

<?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();
                }
        
                
                $conn = @pg_connect("connection details hidden");
                
                $psql="select * from users where username =\"$username\" and 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 help will be apperciated

Link to comment
https://forums.phpfreaks.com/topic/166520-cant-execute-query/
Share on other sites

Don't use @ in code to hide errors, ever. There is absolutely no reason to ever use @ in code. In your code they are probably hiding error messages that would help point out why your code is not working.

 

Also, when learning php (or learning anything new in php), developing php code, or debugging php code, you should have error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you.

Link to comment
https://forums.phpfreaks.com/topic/166520-cant-execute-query/#findComment-878152
Share on other sites

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.