Honesty Rocks! truth rules.

How To Create A "user Profile" Page. No design (easy to add later if you want).

HOME      >>       Programming

Feelay

Hi!

 

It was a long time ago I created a tutorial, so I've decided to create a new one :(

 

This time, I am going to teach you, how to create a "user profile page".

Lets say I am logged in on my account, and want to view someone else account information (in this case, only his username, but you can add more things

later).

Then I'll press on a link, that will take me to his user profile.

But before you can do that, you will have to create a register script, and a login script.

 

If you don't know how to create any of those, you can find tutorials here:

Login-Scipt Tutorial

Register-Script Tutorial

 

You will be using the same database, as the earlier tutorials.

 

Before I start, I just want to say that I would never have learned this, without some guys here on Xisto. So don't give me all the credits.

I think that vujsa, mastercomputers, Mordent and ethergeek, deserve some credits too. Because they teached me some of these things, that I am going to teach

you.

 

------------------------------------------------------------

 

Lets start with the "Member List". To be able to see all the members that's registered on the page, with a link to their profile, we need a member list page.

Lets start with the code.

 

 

Members.php

 

<?phpsession_start();require 'database.php';$nuser=$_SESSION['user'];$auser=$_SESSION['admin'];if($nuser){$userfinal=$nuser;}elseif($auser){$userfinal=$auser;}if(isset($userfinal)){$Members = mysql_query("SELECT user FROM characters WHERE level ='1' ORDER BY exp DESC") or die(mysql_error());$numRowsMembers = mysql_num_rows($Members);?><table border="0"><?phpfor($count = 1; $count <= $numRowsMembers; $count++){ $name = mysql_fetch_array($Members); ?> <tr> <?php echo '<td><a href="member_profile.php?username=' . $name['user'] . '">' . $name['user'] . '</a></td>'; ?> </tr> <?php}?></table>

So.. This is the Member List. I called it "members.php".

I think you want to know what it does, or?

 

The first thing we do, after the PHP tag, is starting a session. Not so hard..

Then we require the database file (I'll add it in the end of this tutorial).

Then, I create two variables.

The "$nuser" is for the "non-admin" user (normal user).

The "$auser" is for the "Admin" user.

After that I've created theese two variables, I check if the user is an Admin, or a Normal user, and insert the $nuser and $auser variable in the $userfinal

 

variable. now it is easy to check if the user is logged in. Instead of first checking if a Normal user is logged in, and then check if an admin is logged, I

 

check if both is logged in, much faster. (hard to explain :P but this way is much easier).

Now this explanation was for the "if(isset($userfinal)){" part.

After that, I create two new variables again.

The first one will get all the "Normal users" from the database.

The other one will retrieve the number of rows from the first query.

 

Then I create an Invisible Table, so that the names looks good, and so that the table don't screw up the design (if you use one.)

But OFC, if you want to make the table visible, you can change the "border" to a number larger than 0.

 

Now after that, we create a for-loop, to show all the names on the screen (the member list), and all the names, will have a link to their profile.

 

 

 

easy, wasn't it? If there is something you didn't understand, you are free to contact me and ask.

Now lets begin with the "member_profile" page.

 

 

 

 

 

member_profile.php

 

 

<?phpsession_start();require 'database.php';$nuser=$_SESSION['user'];$auser=$_SESSION['admin'];if($nuser){$userfinal=$nuser;}elseif($auser){$userfinal=$auser;}if(isset($userfinal)){$username = $_GET['username'];$user = mysql_query("SELECT * FROM user WHERE username = '$username'");$user=mysql_fetch_assoc($user);if($user['level'] > 1){die("You cant view an Admins profile!");}echo "<h1>User Info</h1>";echo "<b>Username:".$user['username']."<br>"; echo "<br>"; echo '<form name="backlistfrm" method="post" action="members.php">'; echo '<input type="submit" value="Back to The List">'; echo '</form>'; echo "<br>";?>

Here we start like we did in the first page.

After the php tag, We start a session, and require the database file.

then we create two variables ($auser = admin and $nuser= normal user).

Then we create the $userfinal variable, to check if the user is logged in later in the script.

Then we create some variables.

 

$username = $_GET['username'];
This is the variable for the name that we pressed on in the member list page.

$user = mysql_query("SELECT * FROM user WHERE username = '$username'");
This variable will select all the info about that person.

$user=mysql_fetch_assoc($user);
This will make us able to select something specific about that person when we are writing the code.

Now we check if the user that we selected is a normal user, or an admin. If the user is an admin, an error will occur that the user can't view the admins

 

profile. If you want you can remove this part:

 

 

if($user['level'] > 1){die("You cant view an Admins profile!");}

This will make the users able to view an admins profile.

 

Then the info about the user will be shown.

In this case, I've only added the username of the user ->

echo "<b>Username:".$user['username']."<br>";

But OFC, you can add more. Just change the user inside the ['...'] to something else from the database table, that you want to show.

 

(lets say you want to show the users Admin level instead of his username, then you can change the $user['username'] to $user['level'].)

 

The last thing I do in this script, is adding a button that will take the user back the the member_list.

 

 

 

And here is the database.php file:

 

<?$con = mysql_connect('localhost','mysql_username','mysql_password');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db('databasename');?>

the first thing we do here, is:

Open a connection to the mysql server.

If the connection failed, the code will write an error

then, we select the database we want to use.

 

 

If you find anything spelled wrong, or any code that I wrote, that is wrong, or if you find something that is not working as it should, paste the wrong

 

word(s) or the wrong code(s) or the error(s), and I'll fix them.

 

Regards //Feelay

 

 

 

 

You are not allowed to copy anything from this tutorial, and paste it outside of this topic, without my permission.

But you are allowed to copy/paste parts of it, inside this topic.


lysvir

Hello!Thank you for the tutorials that you have made. It has helped me a lot with my website.Just one question about this one; I only get "Parse error: syntax error, unexpected $end" in the members profile. It says line 35.Do you think you could help me out ;)? Would be really nice.+Theres no such table as user.characters in your login/registration script either. Whats supposed to be in that one?Thanks


Feelay

Hello!Thank you for the tutorials that you have made. It has helped me a lot with my website.
Just one question about this one; I only get "Parse error: syntax error, unexpected $end" in the members profile. It says line 35.
Do you think you could help me out ;)? Would be really nice.


add this, before the "?>".

} else {echo "You are not logged in. Please log in to continue";}

+Theres no such table as user.characters in your login/registration script either. Whats supposed to be in that one?
Thanks


I think I was using a different database when I created that tutorial.
just change the "user" to the column in your database that takes care of all usernames.
and change characters, to the name of the table you are using to store all the data.


Good luck with you site, and thanks for the comments ;)

lysvir

Now this is my member_profile.php page. Is there something wrong with it as it wont show the username ?
The session name is username and the db file is db.php.

<?phpsession_start();require 'db.php';$nuser=$_SESSION['username'];$auser=$_SESSION['admin'];if($nuser){$userfinal=$nuser;}elseif($auser){$userfinal=$auser;}if(isset($userfinal)){$username = $_GET['username'];$user = mysql_query("SELECT * FROM user WHERE username = '$username'");$user=mysql_fetch_assoc($user);if($user['level'] > 1){die("You cant view an Admins profile!");}echo "<h1>User Info</h1>";echo "<b>Username:".$user['username']."<br>";echo "<br>"; echo '<form name="backlistfrm" method="post" action="members.php">';echo '<input type="submit" value="Back to The List">';echo '</form>';echo "<br>";} else {echo "You are not logged in. Please log in to continue";}?>


Feelay

try to echo the $user = mysql_query("SELECT * FROM user WHERE username = '$username'");

add echo $user; under it.. like this.

$user = mysql_query("SELECT * FROM user WHERE username = '$username'");echo $user;

then write the output of the echo, here.

lysvir

Thanks! Now everything works perfect.
Can I just ask one more question?
Is it hard to make a script within this one, that let's the users upload a profile picture to the database?
I'm currently running everything on localhost with a phpmyadmin system.
I'm thinking something like a profile page that will show:

[PROFILE PICTURE]- [PROFILE NAME]

That this will be shown to the user visiting the profile?
localhost/member_profile.php?username=Test
This will then show the username: TEST and the profile picture that TEST has uploaded.

Is this hard to make?

Feelay

hmm.. I've never really studdied file upload. But it shoudln't be hard to make. You just have to know how to do it. I havn't studdied these things, and therefor, I'm afraid I can't help you =/
sorry. But I am sure that someone else here can.

EDIT: Try searching for UPLOAD PICTURES TO A MySQL DATABASE on Google ;) you should find lots of things.

Here is a good Link =)
Inserting pictures to a mysql database


Wishes //Feelay


lysvir

Thanks for the fast reply, Feelay!I will check it out ^^,


bricktop11

hmm.. I've never really studdied file upload. But it shoudln't be hard to make. You just have to know how to do it. I havn't studdied these things, and therefor, I'm afraid I can't help you =/ sorry. But I am sure that someone else here can.

EDIT: Try searching for UPLOAD PICTURES TO A MySQL DATABASE on Google ;) you should find lots of things.

Here is a good Link =)
Inserting pictures to a mysql database
Wishes //Feelay



Just wondering with legal stuff and all, if any of us used this code on a commerical site would we get sued? or are we freely able to use it?

lysvir

Hi again Feelay.
I'm working on a website that should contain text like this when logged in:
Welcome [username].
But my problem is, how can I make the user see their own profile page just by clicking their username here?
I tried this solution (which didn't work):

at the start:

<?phpsession_start();require_once 'db.php';if (isset($_SESSION['username'])){$user = $_SESSION['username'];?>

Where I wanted the "Welcome [username]" without the "welcome" part:
<h4>Logged in</h4><fieldset><a href = "<?php echo "member_profile.php?username=$user"; ?>"><?php echo $user; ?></a><a href="logout.php">Log out</a></fieldset>

Do you know any working solution for my problem ;)?
Thanks.

Feelay

Just wondering with legal stuff and all, if any of us used this code on a commerical site would we get sued? or are we freely able to use it?

The code is mine. I got some help from people here on Xisto, with some functions. But the whole script is made by me. You are allowed to use it. This is just a beginner script :P So it doesn't really matter :P

Hi again Feelay.I'm working on a website that should contain text like this when logged in:
Welcome [username].
But my problem is, how can I make the user see their own profile page just by clicking their username here?
I tried this solution (which didn't work):

at the start:

<?phpsession_start();require_once 'db.php';if (isset($_SESSION['username'])){$user = $_SESSION['username'];?>

Where I wanted the "Welcome [username]" without the "welcome" part:
<h4>Logged in</h4><fieldset><a href = "<?php echo "member_profile.php?username=$user"; ?>"><?php echo $user; ?></a><a href="logout.php">Log out</a></fieldset>

Do you know any working solution for my problem ;)?
Thanks.

hmm.. I don't understand =/

If you mean what you think you mean, try:

A simple if statement should be able to do it.
If the session user is set, show the welcome, else, show just the name of the user.


If that is not what you mean, please reask the question, but try to explain more ;)

Wishes //Feelay

lysvir

I managed to figure it out by my self ^^,!
This is the code to the profile page:

<?php echo '<td><a href="member_profile.php?username=' . $_SESSION['username'] . '"> Your ingame stats/profile</td>'; ?>


spocrep

thank you so much ... that was a big help...


sozo33

Feelay, this script is great. I'm integrating it into a login/registration script I already have in place and I'm not sure if I'm doing something wrong. The members.php page gives me this error.Parse error: parse error, unexpected $ in ..../members.php on line 34 (which is the end of the script and there is only a </table> tag, but no $ or other php info. My table and fields are slightly different, but I haven't changed anything else. Any thoughts?

<?phpsession_start();require 'include/database.php';$nuser=$_SESSION['user'];$auser=$_SESSION['admin'];if($nuser){$userfinal=$nuser;}elseif($auser){$userfinal=$auser;}if(isset($userfinal)){$Members = mysql_query("SELECT username FROM users WHERE userlevel ='1' ORDER BY exp DESC") or die(mysql_error());$numRowsMembers = mysql_num_rows($Members);?><table border="0"><?phpfor($count = 1; $count <= $numRowsMembers; $count++){ $name = mysql_fetch_array($Members); ?> <tr> <?php echo '<td><a href="member_profile.php?username=' . $name['user'] . '">' . $name['user'] . '</a></td>'; ?> </tr> <?php}?></table>


sozo33

Feelay, this script is great. I'm integrating it into a login/registration script I already have in place and I'm not sure if I'm doing something wrong. The members.php page gives me this error.Parse error: parse error, unexpected $ in ..../members.php on line 34 (which is the end of the script and there is only a </table> tag, but no $ or other php info.

My table and fields are slightly different, but I haven't changed anything else. Any thoughts?

$nuser=$_SESSION['user'];
$auser=$_SESSION['admin'];

if($nuser){
$userfinal=$nuser;
}elseif($auser){
$userfinal=$auser;
}
if(isset($userfinal)){
$Members = mysql_query("SELECT username FROM users WHERE userlevel ='1' ORDER BY exp DESC") or die(mysql_error());
$numRowsMembers = mysql_num_rows($Members);
?>
<table border="0">
<?php
for($count = 1; $count <= $numRowsMembers; $count++)
{
$name = mysql_fetch_array($Members);
?>
<tr>
<?php
echo '<td><a href="member_profile.php?username=' . $name['user'] . '">' . $name['user'] . '</a></td>';
?>
</tr>
<?php
}
?>
</table> linenums:0'><?phpsession_start();require 'include/database.php';$nuser=$_SESSION['user'];$auser=$_SESSION['admin'];if($nuser){$userfinal=$nuser;}elseif($auser){$userfinal=$auser;}if(isset($userfinal)){$Members = mysql_query("SELECT username FROM users WHERE userlevel ='1' ORDER BY exp DESC") or die(mysql_error());$numRowsMembers = mysql_num_rows($Members);?><table border="0"><?phpfor($count = 1; $count <= $numRowsMembers; $count++){ $name = mysql_fetch_array($Members); ?> <tr> <?php echo '<td><a href="member_profile.php?username=' . $name['user'] . '">' . $name['user'] . '</a></td>'; ?> </tr> <?php}?></table>
****UPDATED****
Okay, I realized that the bracket at if(isset($userfinal)){ has two closed brackets in the above code. Being a newbie, I'm not sure where to open another one, or eliminate one of the closed brackets so that they all cancel out. Maybe this will help anyone who looks at this. Thanks in advance!

iGuest

I changed this:---------------------------------------------------------------------------------------------

$Members = mysql_query("SELECT user FROM characters WHERE level ='1' ORDER BY exp DESC") or die(mysql_error());---------------------------------------------------------------------------------------------

  to this---------------------------------------------------------------------------------------------

$Members = mysql_query("SELECT user FROM user WHERE level ='1' ORDER BY exp DESC") or die(mysql_error());---------------------------------------------------------------------------------------------

in member.Php,  than I got this error? "Unknown column 'user' in 'field list'"How do I fix this?------------------------------------------I think I was using a different database when I created that tutorial.Just change the "user" to the column in your database that takes care of all usernames.And change characters, to the name of the table you are using to store all the data.----------------? whot do you mean :P eeeh

 

-reply by UtubeKeywords: create php profile

Danzo0991

cool thanks


hfbvm

i saw a tutorial just like this one on Xisto its quite old.i found it out when i was searching for a free login and registration script.Will have to find it out. :o


iGuest

A step by step tutorial how to create a signin, signup and profile using phpHow To Create A "user Profile" Page.

 I know I am asking too much This "a stet by step tutorials on how to create a sign in page, sign up page or register script and a user profile page". Just like what Freelay posted here. The problem is I'm not a webmaster or a compter expert but I believe that if somebody will make a step by step tuturials I could learn as what I am always doing now. Just for example if somebody will say: First to do is "create a table, then go here and go there, click here and click there, eccc, second create a bla bla bla...And so on...So doing like this I think many peole will be happy like me.

Like me I want this in my website but I don't know how to do it:

that can provides the following facilities:

* Authentication* Signup page* Account confirmation* Login / logout / log as someone else* Edit account* I have lost my login!* I have lost my password!* Delete account
*A profile page which users can edit their account if they want
This is I want to create and put it in my website. I thinking to make a website where anyone can sign up and make their own account and have a website like mine. A website with multiple Users.
Can anybody help me about this or suggest me some tutorials site?
I really need your help guys, Thank you in advance.

-reply by socrates


iGuest

i need a way i can add seperate profiles to each user. Can anyone help?!How To Create A "user Profile" Page.

I'm looking for a system where u log in and I takes u to your profile page in which u can edit.

Ive already got the log in/register stuff sorted but I need profile pages. A bit like myspace of facebook.

If any one knows of anyway to do this please say so or give me a link. Thank you 

-reply by flagman186