Create A Profile Page?, How to create a profile page? I think I'm almost there! |
||
Welcome to the Zymic webmaster forums. Our forums are here to provide people the free ability to discuss a range of websites related topics such as design, development coding and marketing.
In order to post you will need to register for a zymic account or if you already have one simply login by using the form on the left.
Zymic Webmaster Forums Web Design & Development Server Side Scripting PHP |
||
![]() |
Create A Profile Page?, How to create a profile page? I think I'm almost there! |
||
Sep 6 2010, 02:33 PM
Post
#1
|
|
|
Newbie ![]() Group: Members Posts: 12 Joined: 2-May 10 From: Deltona, Florida Member No.: 140,529 |
So... here's what I have...
CODE <?php include('base.php'); $_GET['UserID']; $result = mysql_query("SELECT * FROM users WHERE UserID = 1"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } ?> The $_GET['UserID']; I am not sure serves any purpose yet. WHERE UserID = 1 ... I think "1" needs to be replaced with something. This will show only UserID 1, I want to be able to visit any profile.php page, e.g. profile.php?UserID=4 and for UserID=4 to show that specific user's information. Also, I would like to be able to create a link automatically on a user's account page, such as... Your profile is located at... academic-self-help.zymichost.com/profile.php?UserID=4 for example... Please help with these two tasks, thanks! This is just testing and getting it to work, of course they'll be more information than just first and last name. Which brings me to another task, is it possible for me to allow them to show or hide last name? I would imagine so, I remember using a code that allows you to show or hide email - guess it would work that same way. |
|
|
Sep 8 2010, 05:10 PM
Post
#2
|
|
![]() Super Duper Ninja ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 423 Joined: 24-February 08 Member No.: 11,718 |
Well, you almost have it done. You need to set $_GET['UserID'] to a variable, then you can use that as the id throughout the page. So for instance, $user_id=$_GET['UserID']. Then, for the mysql query, replace the UserID = 1 with UserID = '".$user_id."'
You can then echo $user_id into html code to have the user_id in the html. So for the links, you can just add <?php echo $user_id; ?> where ever you want the user id to be. You can have the user hide anything they want. You can have another database variable called like, "name_hidden" and if its set to 0, then the name is visible. Then in your profile page, make an if/else statement that pulls the info about the users settings, then determines if the name is hidden, and if not, display the name. You can then add an edit settings page where the user can edit these settings anytime they want. I hope this has helped you. |
|
|
Sep 8 2010, 11:31 PM
Post
#3
|
|
|
Outrageously Uber Ninja ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Moderators Posts: 1,805 Joined: 10-July 08 From: UK Member No.: 44,994 |
Why bother assigning the $_GET var? Why not just use it as it is?
And you do need to check it is a number, else bad things will happen. And you need to make sure there is a user with that ID. swordz |
|
|
Sep 20 2010, 06:24 PM
Post
#4
|
|
|
Newbie ![]() Group: Members Posts: 2 Joined: 20-September 10 Member No.: 157,914 |
<?php include('base.php');
$user_id= "$_GET['UserID']"; $result = mysql_query("SELECT * FROM users WHERE UserID = $user_id"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } ?> you can just declare $user_id ="user_id"; instead of he $_GET unless you are pulling it from a URL which i doubt you are. |
|
|
Sep 21 2010, 05:30 AM
Post
#5
|
|
![]() Super Duper Ninja ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 423 Joined: 24-February 08 Member No.: 11,718 |
<?php include('base.php'); $user_id= "$_GET['UserID']"; $result = mysql_query("SELECT * FROM users WHERE UserID = $user_id"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } ?> you can just declare $user_id ="user_id"; instead of he $_GET unless you are pulling it from a URL which i doubt you are. That would just set $user_id to the char "user_id"... if you want it from a post from the previous page, use $_POST['user_id'], wanna use sessions? use $_SESSION['user_id'] |
|
|
Oct 27 2010, 04:41 PM
Post
#6
|
|
![]() Newbie ![]() Group: Members Posts: 10 Joined: 27-October 10 Member No.: 162,964 |
This is a helpful information especially for me that is also a newbie in php.
|
|
|
Nov 18 2010, 08:30 PM
Post
#7
|
|
|
Newbie ![]() Group: Members Posts: 5 Joined: 18-November 10 Member No.: 165,677 |
Just make sure you do:
CODE $userid = mysql_real_escape_string($userid); That will cut the probability of an SQL Injection about in half (AFAIK it can be avoided). EDIT: D: oh darn... just saw that this is a very old topic. Sorry for bumping :C |
|
|
Nov 18 2010, 09:35 PM
Post
#8
|
|
![]() Marvellous Ninja ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 570 Joined: 10-May 09 From: Wisconsin state, United States of America Member No.: 94,482 |
Just make sure you do: CODE $userid = mysql_real_escape_string($userid); That will cut the probability of an SQL Injection about in half (AFAIK it can be avoided). EDIT: D: oh darn... just saw that this is a very old topic. Sorry for bumping :C Hi 7-sided Dice, IMO: Any constructive (updated, or the like) material directly pertinant to a topic is never considered a bump, but rather an enhancement to the already expounded. I think you may be surprised that over the course of time that your injection will prove to be a valuable contribution in this topic to the PHP novice. Crickets! I read it and looked back through the complete thread and I found it useful (for future reference). Thanks. |
|
|
![]() |
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users) |
||
| 0 Members: | ||
Forum Jump |
||
| Lo-Fi Version | Time is now: 20th June 2013 - 09:22 AM |