Jump to content

Can't execute query

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
I've spent days debugging my login script.
the html element on a seperate page is fine.
When a user tries to login and hit submit its returning the "cant execute query".
I can't understand why this is happenning.
Im new to PHP. im using php 5 and not using mysql.

heres my code
<?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 ideas?

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Can you verify that a connection to the database is actually being made? ( that pg_connect is returning a resource and not false)

#3
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
yes a connection is being made.
Ive tested by echoing "connection" if the connection is made

#4
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
change this:

$rs = @pg_query ($psql, $conn)

                    or die ("could not execute query");

so that it echos out an error by doing this:


$rs = @pg_query ($psql, $conn)

                    or die ("could not execute query <br /><br />" . pg_last_error());


let us know the error it displays and we may be able to help you a bit better


from: PHP: pg_query - Manual
Posted Image

#5
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
Thnaks for your help. I did as you said changed the code but an error isn't showing. Just cant execute query. i closed all browser windows after uploading to the server then reloaded the page. I don't know why this is happenning. I'm stumped.

#6
sdavis2702

sdavis2702

    Learning Programmer

  • Members
  • PipPipPip
  • 93 posts
Happy, did you ever figure out what the issue was? I'm curious.
My Name is Sean and I like codes and stuff...
NoobJunction.com | SuccessOnMyMind.com | ArmedForcesCarClub.com