Profile user page

Reply

Join Date: Oct 2009
Posts: 50
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Junior Poster in Training

Profile user page

 
0
  #1
Oct 12th, 2009
I have a register and login code, but i don't know when the user register to automatically make user page.Can anybody help me?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro
 
0
  #2
Oct 12th, 2009
Make a seperate page (profile.php perhaps) and use the unique field in the database (Usually an ID of some sort) in the query string, for example, profile.php?user=usersID.

In the profile.php page, pull the required data from the database and display it as required.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,092
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 137
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster
 
1
  #3
Oct 12th, 2009
Just remember to protect it with a session id, so that you can't change anybody else's profile. View but not edit.
If you don't reply to your own thread or you can't find the solved link - you're off my Christmas list - permanently! Bah humbug!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 50
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Junior Poster in Training
 
0
  #4
Oct 13th, 2009
Can you show me some code examples?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 35
Reputation: nadnakinam is an unknown quantity at this point 
Solved Threads: 0
nadnakinam's Avatar
nadnakinam nadnakinam is offline Offline
Light Poster
 
0
  #5
Oct 13th, 2009
post your code...
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 50
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Junior Poster in Training
 
0
  #6
Oct 13th, 2009
I now how to echo id but how to echo username, email...
This is my code for profile page:
  1. <?php
  2.  
  3. $host="localhost"; // Host name
  4. $username="root"; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name="login4"; // Database name
  7.  
  8. // Connect to server and select database.
  9. mysql_connect("$host", "$username", "$password")or die(mysql_error());
  10. mysql_select_db("$db_name")or die(mysql_error());
  11. $id = $_GET['id'];
  12. $result = mysql_query("SELECT * FROM users WHERE id=$id");
  13. $sql="SELECT * FROM users";
  14. ?>
  15. <?php
  16. echo $id;
  17. ?>
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 50
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Junior Poster in Training
 
0
  #7
Oct 13th, 2009
I now how to echo id but how to echo username, email...
This is my code for profile page:
  1. <?php
  2.  
  3. $host="localhost"; // Host name
  4. $username="root"; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name="login4"; // Database name
  7.  
  8. // Connect to server and select database.
  9. mysql_connect("$host", "$username", "$password")or die(mysql_error());
  10. mysql_select_db("$db_name")or die(mysql_error());
  11. $id = $_GET['id'];
  12. $result = mysql_query("SELECT * FROM users WHERE id=$id");
  13. $sql="SELECT * FROM users";
  14. ?>
  15. <?php
  16. echo $id;
  17. ?>
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro
 
0
  #8
Oct 13th, 2009
Many problems with your code there...

There appears to be no protection on your query at all...
Try replacing this:
  1. $id = $_GET['id'];
with this:
  1. if (is_int($_GET['id'])) {
  2. $id = $_GET['id'];
  3. // Add the rest of the script here.
  4. } else {
  5. // Display an error message, also stop processing.
  6. echo "Error message here";
  7. }

Also, this line $sql="SELECT * FROM users"; is redundant, it does nothing...

Instead of this:
  1. $result = mysql_query("SELECT * FROM users WHERE id=$id");
Try this I added a limit as I assume you will only be expecting one result:
  1. $query = mysql_query("SELECT * FROM users WHERE id=$id LIMIT 1");
  2. $result = mysql_fetch_assoc( $query );
You can then call the values from the DB using $result['field_name'].

So to review, your code should look similar to this:
  1. <?php
  2.  
  3. $host="localhost"; // Host name
  4. $username="root"; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name="login4"; // Database name
  7.  
  8. // Connect to server and select database.
  9. mysql_connect("$host", "$username", "$password")or die(mysql_error());
  10. mysql_select_db("$db_name")or die(mysql_error());
  11. if (is_int($_GET['id'])) {
  12. $id = $_GET['id'];
  13. $query = mysql_query("SELECT * FROM users WHERE id=$id LIMIT 1");
  14. $result = mysql_fetch_assoc( $query );
  15. echo $id;
  16. } else {
  17. // Display an error message, also stop processing.
  18. echo "Error message here";
  19. }
  20. ?>



Also, as ardav said, you will need to add some logic to make sure that the user viewing this page actually has permission to do so, such as creating a session when they login, and check that a session exists when they access this page
Last edited by Will Gresham; Oct 13th, 2009 at 5:28 pm.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 50
Reputation: web3 is an unknown quantity at this point 
Solved Threads: 0
web3 web3 is offline Offline
Junior Poster in Training
 
0
  #9
Oct 13th, 2009
Thanks, xan!
But i still don't now how echo username or email...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 525
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro
 
0
  #10
Oct 13th, 2009
$result['field_name']

Assuming the fields are called email and username, use the following:
$result['email']
$result['username']
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 288 | Replies: 9
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC