firecat318 Posted April 25, 2008 Share Posted April 25, 2008 On my site, each user is allowed to make a small profile to describe themselves a little bit. Basically, I want to assign them a unique URL so that everybody that wants to can visit their profile. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 You need to use a unique identifier in the URL for that user, such as their username or user ID. Then if the URL looks something like this: www.domain.com/profile.php?user=bob Then you can do a query to the database getting the information you need by using their username, which in this case would be "bob". Let me know if you need further explanation. Quote Link to comment Share on other sites More sharing options...
firecat318 Posted April 25, 2008 Author Share Posted April 25, 2008 Alright, I can handle getting the username out of the database, but when I have it, how would I get it into the URL? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 Okay, here is an example. <?php $query = mysql_query("SELECT username FROM table"); $row = mysql_fetch_assoc($query); //put username into link to profile page echo "<a href='profile.php?user={$row['username']}'>Go to {$row['username']}'s Profile</a>"; ?> Now, on the profile page, the code should look like this: <?php //get username from the URL $username = mysql_real_escape_string($_GET['user']); //Get information about that user from database to display profile information $query = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); //Now you can start displaying their profile information with the info from the database. echo "This is {$row['username']}'s Profile page"; ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 No, use $_GET. And be sure to loop through the mysql results. But yeah, use GET not POST. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2008 Share Posted April 25, 2008 No, use $_GET. And be sure to loop through the mysql results. But yeah, use GET not POST. If your talking about my code, I did use $_GET. Also, why loop through the MySQL result when your only expecting one result set? Quote Link to comment Share on other sites More sharing options...
firecat318 Posted April 25, 2008 Author Share Posted April 25, 2008 Okay, here is an example. <?php $query = mysql_query("SELECT username FROM table"); $row = mysql_fetch_assoc($query); //put username into link to profile page echo "<a href='profile.php?user={$row['username']}'>Go to {$row['username']}'s Profile</a>"; ?> Now, on the profile page, the code should look like this: <?php //get username from the URL $username = mysql_real_escape_string($_GET['user']); //Get information about that user from database to display profile information $query = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); //Now you can start displaying their profile information with the info from the database. echo "This is {$row['username']}'s Profile page"; ?> Thanks! That is exactly what I was looking for. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.