Jump to content

username from page to page, and outputting user profile info from table


silverglade

Recommended Posts

Hi , I am trying to get the username from the database and put it into a session variable to be used throughout the website. Also, on the profile page, I want to pull out all the data for that "username" and echo it out onto the screen. for the user that is logged in. But I don't know how to do this. any help greatly appreciated.

 

here is how I am trying to put the current logged in user into a session variable.

 

	//$username is the current logged in user
$query = mysql_query("SELECT username FROM users WHERE username = '$username')");
$_SESSION['currentUser']=$query;

 

now on the profile page, I have no idea how to use $_SESSION['currentUser'] to output the row data for the currentUser like "name" "address" "date of birth" etc.

 

 

Link to comment
Share on other sites

thank you. I don't know how to code it.

 

 

I am trying to put the current logged in user into a session variable to user on future pages.

 

and when I load up the profile page, I want to use mysql to echo out the row of data for that user.

 

Is there something I can google to learn to do this.  I tried "echoing out user data" or "outputting user data" and I can't find anything. When I try to find echoing out table data tutorials, they just show you how to output "*" data in the table. Not specific rows based on username or user id.

 

 

Link to comment
Share on other sites

thank you. I made the profile upload page "logged in only". and it works. But it does not echo out the data for the current logged in user. Here is the code I am trying to echo out the current user's data on that page. $username is declared and set in another file. I used "include" to use it here.

 

EDIT: i spoke too soon. It does output some table data, but not formatted yet, and it looks like it outputs ALL the tables data instead of just the user. but at least its a start!!

 

any more advice appreciated. thanks so far.

 

	$sql = "SELECT username as firstName,lastName,birthday,country,city, state, aboutMe FROM users WHERE  username = '$username'";

						$result = mysql_query($sql);

						if (!$result) {
							echo "Could not successfully run query ($sql) from DB: " . mysql_error();
							exit;
						}

						if (mysql_num_rows($result) == 0) {
							echo "No rows found, nothing to print so am exiting";
							exit;
						}

						// While a row of data exists, put that row in $row as an associative array
						// Note: If you're expecting just one row, no need to use a loop
						// Note: If you put extract($row); inside the following loop, you'll
						//       then create $userid, $fullname, and $userstatus
						while ($row = mysql_fetch_assoc($result)) {
							echo $row["firstName"];
							echo $row["lastName"];
							echo $row["birthday"];
							echo $row["country"];
							echo $row["city"];
							echo $row["state"];
							echo $row["aboutMe"];

						}

						mysql_free_result($result);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.