Hello, I am new to PHP and have been working on a site which I would like to set up some user profiles. I have currently been toying around with the profile page and in order to get better equipped I have been trying to call different information to the tables on the profile page.
I have not had much success. The only success I have is calling the username to the page with this,
if ($_SESSION['username'])
{
echo "You are logged in as ".$_SESSION['username'];
I have been trying to call the users email to the page with similar tags and tags I have found on the internet with no luck.
Does anyone have a general rule of commands or some advice on how I can accomplish tasks as simple as calling information from the DB?
I am at some point trying to set up a gallery for users to upload pictures to there profile and I really need some guidance on how to get there.
Well...the information will only be in $_SESSION if your code put it there. So if you want to access it that way, you'll probably need to modify your login processing to add that data element to the $_SESSION array. Otherwise, you'll need to explicitly query the database for that info in any situation where you need it.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
After this executes it post the most recent person who has registered on the sites information instead of the person who just loged in. I need this to show the persons information who is logged in. Thanks for your help...
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\pixel\profile.php on line 79
Last edited by Nicholas Diaz; 08-26-2012 at 04:58 AM.
if ($_SESSION['username'])
{
echo "You are logged in as ".$_SESSION['username'];
echo "<p>";
echo "<a href='logout.php'>Click to logout</a> <a href='profile.php'>Edit Profile</a>";
}
else
header ("location: index.php");
?>
</font>
</div>
</body>
</html>
How does it know the session username with out me defining any variables on this page.
When I change the $_SESSION['username']; to $_SESSION['email']; I get a syntax error. How come it knows the username and works just fine on every page I include this file on but when I use email there instead it does not know it???
Last edited by Nicholas Diaz; 08-26-2012 at 05:16 AM.
should be before any other code on your page (PHP or HTML) so starting from line 1:
PHP Code:
<?php session_start(); ?>
With regard to it not echoing out the email stored in the session, have you checked you are actually getting an email from the database and that it is being assigned correctly to the session variable:
PHP Code:
echo $row['email']; var_dump($_SESSION); // to view all session data, or var_dump($SESSION['email']) // to just view the email
The undefined index problem generally means that no information is being assigned to the variables, possible a problem with your posted data. Try echoing out the posted data to see if they have any values.
As for the while loop, what you have is incorrect but I also missed a closing bracket in my original code. It should be:
First off thank you so much for all your help... You really are helping me understand a ton and I can tell that this is really close to working.. I am now getting these errors...
Notice: Undefined index: username in C:\xampp\htdocs\pixel\profile.php on line 60
Notice: Undefined index: password in C:\xampp\htdocs\pixel\profile.php on line 61
Notice: Undefined index: phone in C:\xampp\htdocs\pixel\profile.php on line 77
Notice: Undefined index: mobile in C:\xampp\htdocs\pixel\profile.php on line 77
Notice: Undefined index: email in C:\xampp\htdocs\pixel\profile.php on line 77
Notice: Undefined index: web in C:\xampp\htdocs\pixel\profile.php on line 77
This is line 77
echo "<p><b>Username: " . $_SESSION['username'] . "</b><br>Phone: " . $_SESSION['phone'] . "<br>Mobile: " . $_SESSION['mobile']. "<br>E-mail: " . $_SESSION['email'] . "<br>Web: " . $_SESSION['web']. "</p><hr>";
I am pretty sure this is because I am not assigning the variables right when entering the data in to the DB.
That is what I said before, echo out the data you are fetching from your database to ensure you are getting it and the data is correct. So as a temporary measure, in your while loop, comment out assigning to the sessions and echo each row individually.
Run this and see if you have a value for the username and that it is correct. If so change the echo statement to the next value (in this case phone) and run again and so on.
I am assuming this is because I have a registration.php posting data in the data base and then assigning variables.
a login.php doing the same
and then we are working in a profile.php file currently.
So basically what I need to do is make sure the data when posted in the data base has a variable attached to each row.
Then when we log in make sure this information matches.
Then in the profile page in order to call this information make sure they are calling the right variables assigned in the previous files??? From what I am gathering this is how it works???
For instance, when you added $_SESSION its cause you assume based on what I originally sent you that I have already set SESSION up as the variable to call on this information???
Bookmarks