how to display a member's information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hasanoca
Forum Newbie
Posts: 9
Joined: Fri Mar 05, 2010 4:42 am

how to display a member's information

Post by hasanoca »

Hello;
I have been searching the google for the answer with no satisfactory outcome and needed human understanding. The question is how can I display a member's information to that member only and apply this to each member. I don't want to write a code for each member one by one, which I can do using something like

Code: Select all

$result = mysql_query("select * from users
WHERE username='THEUSERNAME'") or die(mysql_error());
but I want to insert something in place of THEUSERNAME which will display the information for each specific user.
I need something like the user control panel of this forum or something much simpler.
I have created a database and table. That is all. I would be pleased if your answers were simple enough to address the newbie that I am :roll: .
hasanoca
Forum Newbie
Posts: 9
Joined: Fri Mar 05, 2010 4:42 am

Re: how to display a member's information

Post by hasanoca »

Well, I found it somehow. This is how it is to be done;

Code: Select all

$uname = $_SESSION['username']; 
$result = mysql_query("SELECT * FROM users
where username = '$uname'") or die(mysql_error());
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: how to display a member's information

Post by John Cartwright »

Code: Select all

$result = mysql_query("SELECT * FROM users WHERE username = '". mysql_real_escape_string($uname) ."' LIMIT 1");
You always want to use mysql_real_escape_string() in input to avoid SQL injection. Plus, I find it's always good practice to LIMIT your queries if you are only expecting x rows returned (unless querying your primary key).
Post Reply