Jump to content

puzzling error in pgsql / php

- - - - -

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

<?php

if(isset($_POST['username'])) {

    $conn = @pg_connect("host=**********.****.**.** user=****** password=********** dbname=******");

   $psql = "SELECT * FROM users WHERE username = '".$_POST['username']."' AND password = '".$_POST['password']."'";

   $result = pg_query($psql, $conn);

   $count = pg_num_rows($result);

   

   if($count < 1) {

      

      echo "Wrong username or password";

      

   } else {

      

      echo "Successfully logged in";

   }

   

}

?>



and the error is

Warning: pg_query(): supplied argument is not a valid PostgreSQL link resource in /home2/webusers/07/344740/public_html/sporticket/login2.php on line 5

Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL result resource in /home2/webusers/07/344740/public_html/sporticket/login2.php on line 6

any thoughts?
help is always appreciated

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Missing @ symbols?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
with the @ in it didnt work.
i took em out 2 see if i got more errors

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
"supplied argument is not a valid PostgreSQL link resource in"
is normally the error provided when the query generates errors.
print the error message and see what that can do. try
$result = pg_query($psql, $conn) or die(pg_last_error($conn)); 
instead ofyour pg_query, and see that error message given.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#5
happy

happy

    Newbie

  • Members
  • PipPip
  • 25 posts
thanks for your help

after doing what suggested i get this mesage


Warning: pg_query(): supplied argument is not a valid PostgreSQL link resource in /home2/webusers/07/344740/public_html/sporticket/login2.php on line 6

#6
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
Have you verified that the supplied argument is a valid PostgreSQL link resource? The PHP manual says that pg_connect returns a "PostgreSQL connection resource on success, FALSE on failure." I would start by checking to see if $conn is indeed a valid resource. If $conn is FALSE it is obviously not a valid resource and your problem lies within your connection to the database. If it is a resource, I would take a closer look at the supplied arguments. Here is a snippet from the PHP manual that should shed a lot of light on your issue.

resource pg_query  ([ resource $connection  ], string $query  )
Note the parameter ordering.

WingedPanther said:

Missing @ symbols?
The @ symbol is used to suppress errors/warnings.