Jump to content

Link to profile page


Pain

Recommended Posts

Hello.

 

Say i want to view another user profile. I click on user name and i see the profile page.

So how can i link user name to his profile?

 

I have tried linking it to $id (this is where user id is stored in the database), but no luck.

 

Thank you.

Link to comment
Share on other sites

Sorry.

I am trying to link $view_user to the profile page. First part of code displays all users. When i click on any of users i want to see info about this particular user.

 

<?php
$query = mysql_query("SELECT * FROM users2 WHERE username = '$usr'");
$numrows = mysql_num_rows($query);


if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$view_user = $row['username'];
$id2 = $row['id'];


echo "<a href='main.php?id=profile'>$view_user</a>";

}
}



?>

My profile page is set to display info of the session user:

<?php
$query = mysql_query("SELECT * FROM users2 WHERE username = '$usr'");
$numrows = mysql_num_rows($query);


if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$view_power = $row['power'];
$view_speed = $row['speed'];
$view_money = $row['money'];
$view_user = $row['username'];
$usr = $_SESSION['username'];
$id2 = $row['id'];


echo "<br /><br /><b>Personal information</b><br />";
echo $view_user . "<br /><br />";
echo "<b>In Game Stats</b><br />";
echo "Money: " . $view_money . "<br />";
echo "Strength: " . $view_power . "<br />";
echo "Speed: " . $view_speed . "<br />";



}
}



?>

Link to comment
Share on other sites

You aren't linking anything but the word 'profile'

 

echo "<a href='main.php?id=profile'>$view_user</a>";

 

try this

echo "<a href='main.php?id=$id2'>$view_user</a>";

 

I have this code on my main page

$id = $_GET['id'];

if ($id == profile) {
include("profile.php");
}

this allows me to hold everything in my main page, thats why going to main.php?id=profile is generally working, but it doesn't show any user info.

 

main.php?id=$id2 displays the correct ID in the address bar, but when i click the link it says that the page does not exist

 

Link to comment
Share on other sites

<?php

session_start(); // Session starts here
if(!isset($_SESSION['username'])) // If there is no session then...
{
    die ("<div align='center'><img src='images/LOGINKITTEN.jpg'/><br /><a href='index.php'><img src='images/Login.jpg'/></a></div>"); // ...Die!
} 

$usr = $_SESSION['username'];
$view_money = $_SESSION['money'];
$id2 = $_SESSION['id'];




?>
<html>
<head>

<link rel="stylesheet" type="text/css" href="css.css" />


</head>

<?php


$connection = mysql_connect("localhost", "abcdef_db", "abcdef") or die ("Could not connect");
mysql_select_db("abcdef", $connection) or die("Could not connect");

$query = mysql_query("SELECT * FROM users2 WHERE username = '$usr'");
$numrows = mysql_num_rows($query);

if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$view_money = $row['money'];
$view_speedmain = $row['speed'];
$view_powermain = $row['power'];


}
}

echo "<br /><br /><a href='main.php?id=fighters'>Fighters</a>   ||   ";
echo "<a href='main.php?id=training'>Training</a>   ||   ";
echo "<a href='main.php?id=robform'>Rob Money</a>   ||   ";
echo "<a href='main.php?id=buyweapons'>Buy Weapons</a>   ||   ";
echo "<a href='main.php?id=profile'>Profile</a>   ||   ";
echo "<a href='main.php?id=logout'>Logout</a><br />";

$id = $_GET['id'];

if ($id == training) {
include("training.php");
}
if ($id == fighters) {
include("fighters.php");
}
if ($id == fight) {
include("fight.php");
}
if ($id == topstrength) {
include("topstrength.php");
}
if ($id == topspeed) {
include("topspeed.php");
}
if ($id == logout) {
include("logout.php");
}
if ($id == addmoney) {
include("addmoney.php");
}
if ($id == buyweapons) {
include("buyweapons.php");
}
if ($id == robform) {
include("robform.php");
}
if ($id == topmoney) {
include("topmoney.php");
}
if ($id == topmoney) {
include("topmoney.php");
}
if ($id == profile) {
include("profile.php");
}
        echo "You are logged in as " . $usr;
	echo " ||  Your Balance " . $view_money . "$";
	echo " ||  Strength " . $view_powermain;
	echo " ||  Speed " . $view_speedmain;
?>

       



</body>
</html>

Link to comment
Share on other sites

everyuser should have a unique id store in the db once they sign-up. that unique id will be their profile id. so for example, if you would like to view a user, i would recommend you to create a page called profile.php and use the get function to get the id which is given. if there is no id given, show the user's profile instead.

 

<?php

session_start();

if(empty($_GET['id']) || !empty($_SESSION['username'])) {

// mysql query for user's id and etc

}

else {

//mysql query for $id and etc
$id = $_GET['id'];

}

?>

Link to comment
Share on other sites

<?php
session_start(); // Session starts here
if(!isset($_SESSION['username'])) // If there is no session then...
{
    die ("<div align='center'><img src='images/LOGINKITTEN.jpg'/><br /><a href='index.php'><img src='images/Login.jpg'/></a></div>"); // ...Die!
} 

$usr = $_SESSION['username'];
$uniqueid = $_GET['id'];




$connection = mysql_connect("localhost", "866075_db", "dbbbb") or die ("Could not connect");
mysql_select_db("866075_db", $connection) or die("Could not connect");

$query = mysql_query("SELECT * FROM users2 WHERE username = '$usr'");
$numrows = mysql_num_rows($query);


if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$view_power = $row['power'];
$view_speed = $row['speed'];
$view_money = $row['money'];
$view_user = $row['username'];
$usr = $_SESSION['username'];
$id2 = $row['id'];
$i++;
$victories = $row['victorycount'];


echo "<br /><br /><b>Personal information</b><br />";
echo $view_user . "<br /><br />";
echo "<b>In Game Stats</b><br />";
echo "Money: " . $view_money . "<br />";
echo "Strength: " . $view_power . "<br />";
echo "Speed: " . $view_speed . "<br />";
echo "Victories: " . $victories . "<br />";



}
}



?>

Whenever i click on any user, it still displays the info of the user that is logged in

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.