Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
In my code
PHP
<?php
 session_start(); 
mysql_connect("host","username","password");
mysql_select_db("database");

$id = $_GET['id'];
?>
<?php print htmlentities($_SESSION['dbUser']['id'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['username'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['fname'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['lname'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['email'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['rank'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['picture'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['dob_month'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['dob_day'], ENT_QUOTES, 'UTF-8'); ?><br>
<?php print htmlentities($_SESSION['dbUser']['dob_year'], ENT_QUOTES, 'UTF-8'); ?>

It only echos the id, the username, and the email address...How could i fix this?
Posted
Comments
enhzflep 24-Nov-13 9:06am    
Hard to say. Are you sure the other fields actually contain something?

What's the result of <?php var_dump($_SESSION['dbUser']);?>?
Member 10421693 24-Nov-13 9:13am    
It said
array(3) { ["id"]=> string(1) "1" ["username"]=> string(5) "Admin" ["email"]=> string(18) "admin@example.com" } ?
enhzflep 24-Nov-13 9:26am    
Okay then, that confirms my suspicion - the other fields don't exist.
I'd have a closer look at the part of your code that sets id, username and email - you've either forgotten to set the other values or the variables that you think hold the data, dont actually have anything in them. - I'm not actually sure what happens try to set an array e;lement with the contents of a variable that's undefined or null.
Member 10421693 24-Nov-13 9:34am    
But the database is filled properly and has the fname and lname etc. filled
enhzflep 24-Nov-13 9:51am    
I'm sure it does. But you still have to get the information from the database and put it into the $_SESSION variable at some point.

The code you've shown above doesn't perform this task - that happens somewhere else. So, as I suggested earlier - find the part of the code that does put the id,username & email values into the $_SESSION variable.

1 solution

The problem ended-up being solved via a discussion in the comments section, however in the interests of removing it from the unanswered questions list, I'll try to summarize the problems and the steps taken to mediate them.

As the question indicates, only a few of the requested fields of the $_SESSION variable were holding any data, as confirmed by the use of var_dump.

After looking for the place in the code that the assignment was made to the $_SESSION var, it was found that all of the available data was added in a single statement - one which assigned the row returned by an SQL query.

Upon yet closer inspection, it seemed that of the 10 expected values, only three of them were actually requested. That is to say, rather than a "SELECT * FROM _someTable_ WHERE _someCondition" type query, the actual query was more along the lines of "SELECT _field1_, _field2_, _field3_ FROM _someTable_ WHERE _someCondition_"


A reasonably easy fix in retrospect. Just remember kids - remote-debugging, M.U.D - style at 4am isn't a wise idea. It's probably also a good idea, when writing parts A & B, where B depends on A, to make sure A is doing what you think it is before moving onto step B.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900