Pain Posted November 16, 2011 Share Posted November 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/ Share on other sites More sharing options...
Pain Posted November 16, 2011 Author Share Posted November 16, 2011 someone? Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288752 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Share Posted November 16, 2011 You haven't provided anything other than what you want to do. Provide some code of some sort so that we can see what your issue is Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288756 Share on other sites More sharing options...
Pain Posted November 16, 2011 Author Share Posted November 16, 2011 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 />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288762 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Share Posted November 16, 2011 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288765 Share on other sites More sharing options...
Pain Posted November 16, 2011 Author Share Posted November 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288771 Share on other sites More sharing options...
Pain Posted November 16, 2011 Author Share Posted November 16, 2011 the problem is that there is nothing in on the page when i redirect to id=$id. I suppose i should implement something like automatic page creation for $id? Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288799 Share on other sites More sharing options...
Pain Posted November 16, 2011 Author Share Posted November 16, 2011 To clarify this: i need to create a unique link for every user, so that other can view the profile. Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288805 Share on other sites More sharing options...
litebearer Posted November 16, 2011 Share Posted November 16, 2011 Show us the ENTIRE main.php page Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288807 Share on other sites More sharing options...
Pain Posted November 16, 2011 Author Share Posted November 16, 2011 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288808 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 17, 2011 Share Posted November 17, 2011 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']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1288882 Share on other sites More sharing options...
Pain Posted November 18, 2011 Author Share Posted November 18, 2011 Done that. Still have no idea how to set up this unique link to users profile. Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1289262 Share on other sites More sharing options...
Pain Posted November 18, 2011 Author Share Posted November 18, 2011 Ok so the unique link is set for each user. For instance profile.php?id=3 But how do i display info from DB in the web. There's something wrong with my profile page i suppose. Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1289267 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 18, 2011 Share Posted November 18, 2011 yes, each user have the unique id. what is in your profile.php as of now? Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1289269 Share on other sites More sharing options...
Pain Posted November 18, 2011 Author Share Posted November 18, 2011 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1289302 Share on other sites More sharing options...
Pain Posted November 18, 2011 Author Share Posted November 18, 2011 i figured this out by myself Quote Link to comment https://forums.phpfreaks.com/topic/251263-link-to-profile-page/#findComment-1289325 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.