Jump to content

Giving each profile its own URL?


firecat318

Recommended Posts

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.

Link to comment
Share on other sites

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";

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.