Nov 21, 2009
Pages: 1, 2, 3

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

free web hosting

Read Latest Entries..: (Post #22) by starscream on Nov 3 2009, 08:13 PM.
Nice tutorials freelay. Didn't knew they were here in astahost. I think i need to look for threads by searching now. Thanks for thread-bump hannah.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

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

Feelay
Hi!

It was a long time ago I created a tutorial, so I've decided to create a new one wink.gif

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 Astahost. 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

CODE
<?php
session_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">

<?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>



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 tongue.gif 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


CODE
<?php
session_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.


CODE
$username = $_GET['username'];
This is the variable for the name that we pressed on in the member list page.
CODE
$user = mysql_query("SELECT * FROM user WHERE username = '$username'");
This variable will select all the info about that person.
CODE
$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:



CODE
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 ->

CODE
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:

CODE
<?
$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.


 

 

 


Comment/Reply (w/o sign-up)

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 smile.gif? 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

Comment/Reply (w/o sign-up)

Feelay
QUOTE(lysvir @ Sep 14 2008, 01:38 AM) *
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 smile.gif? Would be really nice.


add this, before the "?>".

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


QUOTE(lysvir @ Sep 14 2008, 01:38 AM) *
+
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 smile.gif

 

 

 


Comment/Reply (w/o sign-up)

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.
CODE
<?php
session_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";
}

?>

Comment/Reply (w/o sign-up)

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

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

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


then write the output of the echo, here.

Comment/Reply (w/o sign-up)

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:
CODE
[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?




Comment/Reply (w/o sign-up)

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 biggrin.gif you should find lots of things.

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


Wishes //Feelay

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

bricktop11
QUOTE(Feelay @ Sep 17 2008, 09:14 PM) *
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 biggrin.gif 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?

Comment/Reply (w/o sign-up)

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:
CODE
<?php
session_start();
require_once 'db.php';
if (isset($_SESSION['username'])){
$user = $_SESSION['username'];
?>


Where I wanted the "Welcome [username]" without the "welcome" part:
CODE
<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 smile.gif?
Thanks.

Comment/Reply (w/o sign-up)

Latest Entries

starscream
Nice tutorials freelay. Didn't knew they were here in astahost. I think i need to look for threads by searching now. Thanks for thread-bump hannah.

Comment/Reply (w/o sign-up)

HannahI
Now, I got another good site. biggrin.gif

Comment/Reply (w/o sign-up)

surfermac
good tutorials freelay
keep on with such tutorials
as you spread your knowledge

Comment/Reply (w/o sign-up)

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

Comment/Reply (w/o sign-up)

iGuest
A step by step tutorial how to create a signin, signup and profile using php
How 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


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2, 3
Similar Topics

Keywords : User Profile

  1. Simple User Validation Script - (7)
    This tutorial will show you how to create a simple user validation script with PHP. We will need
    two files: "protect.php" and "login.php". The protect file is not meant to be viewed by itself. In
    order to protect a page, you need to include that file by using PHP code like the following: CODE
    include("protect.php"); Keep in mind that this needs to be in between your tags. This bit of
    code uses the include function. It is a handy function that reads all the information contained in
    one file and temporarily adds it to another. For example, this can be used to cr...
  2. How To: Display A Members/user List. - With PHP, Mysql, and HTML. (4)



Looking for create, user, profile, page, design, easy, add,

See Also,

*SIMILAR VIDEOS*
Searching Video's for create, user, profile, page, design, easy, add,
advertisement



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

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com