Hello, Im working on a website, where a user can have their own profile. I have a .home.php where the user can view their profile. To view other peoples profile, I would like it to be structured as follows: home.php?userid=2 how would I go about doing that? Thank you for your help, -Tim
you could do it the easy way: $userid = $_GET["userid"]; if(!is_numeric($userid) || $userid==""){ $userid = logged in user id; } Code (markup): then use $userid in your queries
Hello, Here's some help for you, I took the liberty of writing an example for you below. <?php // Home.php if(isset($_GET['userid']) && !empty($_GET['userid']) && is_numeric($_GET['userid'])) { $userid = trim($_GET['userid']; $sql = "SELECT * FROM users WHERE userid='".mysql_real_escape_string($userid)."'"; $result = mysql_query($sql); $num = mysql_num_rows($result); $row = mysql_fetch_array($result); if($num == 1) { $firstname = stripslashes($row['firstname']); // Rest of the variables } } HTML DATA HERE Simply echo the data onto the page we retrieved where ever applicable. <html> <head> <title><?=$row['firstname']?>'s Home Page</title> </head> <body> <p>Welcome to <?php echo $row['firstname'];?>'s Home Page.</p> </body> </html> ?>
Great, thank you both so much. Now as for building the url...how would that work? if i typed in example.com/home.php?user=1 how would it know to display userid 1's data? If the above example just answered my question, i do apologize, still learning
Yep the example I gave answered your question. The principle is the data is stored in the database and each user has a userid. You simply query the database with the userid like my example and retrieve the information for that user. You will of course have to ensure all data is secured..
My friend, you rock my socks. Thank you greatly. You did forget a closing parenthesis on line 8 tho. not trying to point that out, but for others who follow along may not see it. $userid = trim($_GET['userid']); +rep for all your help! works like a charm.
Im having a small issue... when i switch between viewing profiles and my edit profile area, some variables are getting stuck as the other viewers and not my own. e.g. I'm logged in as "Tim" and view my profile. My userid is 1. I switch to see "Bryan's" profile. His user id is 2. I then switch back to view my edit profile area, but my userid is showing as "2" and not 1. how do i keep my variables mine, and their variables theirs? thanks for all your help!! -Tim
Are you setting some kind of cookie when the user views someone else's profile? If you are, you should only need to set the cookie for the logged in member, and use the querystring variable if available. My example actually showed this method.
I wouldn't use cookies for that type of data storage unless it's encrypted. Just use session variables and you will be absolutely fine. Good luck and let me know if you need any more help. - Dwayne.