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

  • SEARCH
  • Home
  • 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 6954991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:40:45+00:00 2026-05-27T14:40:45+00:00

function StoreUserProfileInSession( $username, $password ) { session_start(); $query = pg_query( SELECT * FROM mytable

  • 0
function StoreUserProfileInSession( $username, $password )
{
        session_start();
        $query = pg_query( "SELECT * FROM mytable where username = '$username' AND password = '$password'" );

        $rows = pg_fetch_array( $query );

        foreach( $rows as $key => $value )
        {
            if( $key == 'password' ) //do not store password in session because it's DANGEROUS!
                continue;

            $_SESSION[$key] = $value;
        }
}

After this function is being called i am redirected to my frontend.
When I try to print_r($_SESSION); in there I only got a one value in session, and that is the user_id, I have many fields in my table.

Why am I only getting one value? what’s wrong with this?

Any help or idea would be greatly appreciated and rewarded!
Thanks! 🙂

  • 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-27T14:40:46+00:00Added an answer on May 27, 2026 at 2:40 pm

    Two things:

    1. pg_fetch_array() is not returning what you expect.
    2. $_SESSION cannot have any key name that could not also be a php variable name.

    $rows looks like this:

    $rows = array(
        'user_id' => 1
        1,
        'password' => 'THE PASSWORD',
        'THE PASSWORD',
    );
    $rows['user_id'] === $rows[0];
    // etc
    

    Thus in your foreach loop, right after the user_id key, you are actually doing this:

    $_SESSION[0] = 1;
    

    This is illegal, so the session object stops working.

    Instead do this:

    // PGSQL_ASSOC says, "only return named keys, not numeric keys"
    $therow = pg_fetch_array($query, null, PGSQL_ASSOC);
    unset($therow['password']);
    $_SESSION['user'] = $therow;
    pg_free_result($query);
    
    
    // get user data like this:
    $_SESSION['user']['user_id']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function toltalRetailerComm($userId) { //print_r ($shoppeId); $sql = SELECT shoppe_id FROM atm_super_shoppe WHERE user_id='$userId'; $query
function get_total_adults() { $sql = SELECT SUM(number_adults_attending) as number_of_adults FROM is_nfo_rsvp; $result = mysql_query($sql)
function dowork() { $(.wrappedElement).removeClass(wrappedElement); $(.wrappedElementout).removeClass(wrappedElementout); var a=$(div#DepPart select option:selected).val(); $(div#TestPart select option[value^=a]).addClass(wrappedElement); $(div#TestPart select
function GetMe(id) { DB.transaction( function (transaction) { transaction.executeSql(SELECT * FROM users WHERE id =
function logsig() { var username = $(#username).val(); var password = $(#password).val(); var dataString =
function getUsername() { var userName = document.form.screen_name.value; document.getElementById(display).innerHTML = userName; var apiName = https://api.twitter.com/1/users/lookup.json?screen_name=
function heaviside(&$value, $key, &$array) { if($key > 0) $value = $array[$key-1].$array[$key]; } function test_heaviside()
function countJSONObjByKeyValue(obj, key, value) { var countJSONShows = 0; $.each(obj, function(i, item) { if(obj[i].key
function register_contact ($person = array()) { $nogood = false; foreach ($person as $val) {
function(char* name) { char sql[50]; sprintf(sql, select %s;, name); } What's the best way

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.