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.

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

?>

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.