Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:49:48+00:00 2026-05-23T15:49:48+00:00

I am writing a simple user/login system in Php with postgresql. I have a

  • 0

I am writing a simple user/login system in Php with postgresql.

I have a function that confirms whether username/passwords exists, which gets activated when a user presses the Login button.

 public function confirmUserPass($username, $password){

    $username=pg_escape_string($username);

    /* Verify that user is in database */

    $q = "SELECT password FROM users WHERE email = '$username'";
    $result = pg_query($this->link,$q);

    /* Do more operations */
}

I want to print the query stored in $results such that I can see it on the browser. When I do it in phppgAdmin using SQL it shows me the output but I cannot see it on the browser. I tried echo and printf but I could not see anything on the browser. I also tried to see view source from the browser but it shows nothing.
Can somebody help me with that?

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:49:49+00:00Added an answer on May 23, 2026 at 3:49 pm

    From your code: $result = pg_query($this->link,$q);

    As you’ve found already, trying to display the contents of $result from the line above will not give you anything useful. This is because it doesn’t contain the data returned by the query; it simply contains a “resource handle”.

    In order to get the actual data, you have to call a second function after pg_query(). The function you need is pg_fetch_array().

    pg_fetch_array() takes the resource handle that you’re given in $result, and asks it for its the next set of data.

    A SQL query can return multiple results, and so it is typical to put pg_fetch_array() into a loop and keep calling it until it returns false instead of a data array. However, in a case like yours where you are certain that it will return only one result, it is okay to simply call it once immediately after pg_query() without using a loop.

    Your code could look like this:

    $result = pg_query($this->link,$q);
    $data = pg_fetch_array($result, NULL, PGSQL_ASSOC);
    

    Once you have $data, then you’ve got the actual data from the DB.

    In order to view the individual fields in $data, you need to look at its array elements. It should have an array element named for each field in the query. In your case, your query only contains one field, so it would be called $data['password']. If you have more fields in the query, you can access them in a similar way.

    So your next line of code might be something like this:

    echo "Password from DB was: ".$data['password'];
    

    If you want to see the raw data, you can display it to the browser using the print_r() or var_dump() functions. These functions are really useful for testing and debugging. (hint: Wrap these calls in <pre> tags in order for them to show up nicely in the browser)

    Hope that helps.

    [EDIT: an after-thought]

    By the way, slightly off-topic, but I would like to point out that your code indicates that your system may not be completely secure (even though you are correctly escaping the query arguments).

    A truly secure system would never fetch the password from the database. Once a password has been stored, it should only be used in the WHERE clause when logging in, not fetched in the query.

    A typical query would look like this:

    SELECT count(*) n FROM users WHERE email = '$username' AND password = '$hashedpass'
    

    In this case, the password would be stored in the DB as a hashed value rather than plain text, and the WHERE clause would compare that against a hashed version of the password that has been entered by the user.

    The idea is that this allows us to avoid having passwords accessible as plain text anywhere in the system, which reduces the risk of hacking, even if someone does manage to get access to the database.

    It’s not foolproof of course, and it’s certainly not the whole story when it comes to this kind of security, but it would definitely be better than the way you seem to have it now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple auth system to login (and logout) users. The username is
I'm writing a simple app that's going to have a tiny form sitting in
I'm writing an application in PHP that uses forms to retrieve the username and
I'm writing some user-JS for Opera. It reacts on a request that doesn't have
I'm writing a simple app that takes standard input from the user. As for
I am writing a simple WinForms application in which I allow the user to
I'm writing a simple iPhone app which lets a user access a series of
I am writing simple site that requires users and profiles to be handled. The
I'm writing a simple OpenGL application that uses GLUT . I don't want to
I am currently writing a simple, timer-based mini app in C# that performs an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.