Jump to content

[SOLVED] User Profiles, how can i .....


DeanWhitehouse

Recommended Posts

i have a user profile page, this page works by checking the users session_id and then gets this data from the database. Now how can i display this to other users, for example, so other users can view other users profiles(this is a really bad explanation).

 

this is my current page

<?php
require_once 'db_connect.php';
require_once 'nav_bar.php';
require_once 'logged_in.php';

if ($_SESSION['is_valid'] == true){

$user_id = $_SESSION['user_id'];
$sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$username = $row['user_name'];
$email = $row['user_email'];
echo "$username<br>";
$show_email = $row['show_email'];
if ($show_email == 1)
{ 
echo "Username:<a href='mailto:$email'>$email</a>";
}
elseif ($show_email == 0)
{
echo "Email:Hidden";
}
}
else
{
echo "Please login to view this page.";
}
?>

Link to comment
Share on other sites

Make a page named like profile.php and have links like profile.php?id=123.  Then on the page, do:

<?php
if (isset($_GET['id'])) {
//query and stuff with this ID
}
else {
echo "Invalid user ID passed to page!";
}
?>

 

Basically, substitute $_SESSION with $_GET in your code. =P

Link to comment
Share on other sites

is this the right thing

 

<?php
if (isset($_GET['id'])) {
$user_id = 'id';
$sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$username = $row['user_name'];
$email = $row['user_email'];
echo "$username<br>";
$show_email = $row['show_email'];
if ($show_email == 1)
{ 
echo "Email:<a href='mailto:$email'>$email</a>";

}
elseif ($show_email == 0)
{
echo "Email:Hidden";
}
}
else {
echo "Invalid user ID passed to page!";
}
?>

<a href="?id=1">Blade</a>

Link to comment
Share on other sites

No.

<?php
if (isset($_GET['id'])) {
$user_id = $_GET['id'];
$sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$username = $row['user_name'];
$email = $row['user_email'];
echo "$username<br>";
$show_email = $row['show_email'];
if ($show_email == 1)
{ 
echo "Email:<a href='mailto:$email'>$email</a>";

}
elseif ($show_email == 0)
{
echo "Email:Hidden";
}
}
else {
echo "Invalid user ID passed to page!";
}
?>

 

There.  NOW, to access this page, it'd be:

<a href="profile.php?id=1">Blade</a>

Assuming that the page is named profile.php.  You'd probably make these links on a userlist page and dynamically insert the ID to link to their profile.

Link to comment
Share on other sites

i think i might be able to "dynamically create links" but i'm not sure, do i just make an echo for each link and then it will only display them if they are in the database?

 

Here...

<?php
if (isset($_GET['id'])) {
if ((int) $_GET['id'] > 0) {
$user_id = $_GET['id'];
$sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$username = $row['user_name'];
$email = $row['user_email'];
echo "$username<br>";
$show_email = $row['show_email'];
if ($show_email == 1)
{ 
echo "Email:<a href='mailto:$email'>$email</a>";

}
elseif ($show_email == 0)
{
echo "Email:Hidden";
}
exit();
}
else {
echo "Invalid user ID passed to page! <br />";
echo "<a href=\"profile.php\">Return to user list</a>";
exit();
}
}
//No ID passed to page, display user list:
$query = "SELECT user_id, user_name FROM $user";
$result = mysql_query($query) or die("Error:" . mysql_error());
if (mysql_num_rows($result) > 0) {
echo "User List:<br />";
while ($row = mysql_fetch_assoc($result)) {
  echo '<a href="profile.php?id=' . $row['user_id'] . '">' . $row['user_name'] . '</a><br />';
}
}
?>

 

I hate to do it for you, but there you go.  Might be syntax error somewhere, not sure, and you might want to change something at some point, so you can if you want, lol.  It should work like that though.  Save it as profile.php.

 

Link to comment
Share on other sites

thanks, i think i was close

mine was

<?php
require_once 'db_connect.php';
if (isset($_GET['id'])) {
$user_id = $_GET['id'];
$sql = "SELECT * FROM $user WHERE `user_id`='{$user_id}' LIMIT 0,1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$username = $row['user_name'];
$email = $row['user_email'];
echo "$username<br>";
$show_email = $row['show_email'];
if ($show_email == 1)
{ 
echo "Email:<a href='mailto:$email'>$email</a>";

}
elseif ($show_email == 0)
{
echo "Email:Hidden";
}
}
?>
Members
<?php 
$sql1 = "SELECT * FROM $user WHERE `user_name` AND `user_id`";
$result1 = mysql_query($sql1);
$row1 = mysql_fetch_assoc($result1);
$username1 = $row1['user_name'];
$userid = $row1['user_id'];
?>
<a href="?id=<?php echo "$userid"; ?>"><?php echo "$username1"; ?></a>

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.