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! 🙂
Two things:
pg_fetch_array()is not returning what you expect.$_SESSIONcannot have any key name that could not also be a php variable name.$rowslooks like this:Thus in your foreach loop, right after the
user_idkey, you are actually doing this:This is illegal, so the session object stops working.
Instead do this: