Jayden_Blade Posted November 20, 2013 Share Posted November 20, 2013 I am trying to view a different users profile. I am able to view mine. I did this 2 years ago.... I cant remember. Here is my php code. What do i have to put in url to see others profile? <?php /* DONE DONE DONE DONE DONE DONE DONE * How to display profile page. * Check if the user is viewing ANOTHER user's profile * and if so, display that profile, otherwise display the * user's own profile */ session_start(); if (!$_SESSION || !$_SESSION['login']) { //redirect to a login page header('Location: index.php'); exit; } //echo $username; //echo $userid; error_reporting(E_ALL); include ('database.php'); //Get userid that matches username in table to username in url //$exists = mysql_query("SELECT `username` FROM `user` WHERE `username`='$_GET[user]' LIMIT 1"); //$exists1 = mysql_fetch_assoc($exists); if ($_GET){ $result = mysql_query("SELECT `userid` FROM `user` WHERE `username`='$_GET[user]' LIMIT 1"); //returns the results from the mysql database in an associative array format $profileusername = mysql_fetch_assoc($result); // RE assigns $profileusername value to $profileID $profileID = $profileusername['userid']; //assigns $_GET username to $username $username = $_GET['user']; //} //elseif($username === $exists1);{ $resulta = mysql_query("SELECT `age`,`sex`,`sexpref`,`maritalstatus`,`location`,`lookingfor`,`children`,`smoking`,`drinking`,`lastlog`,`profileimagelocation` FROM `profiledata` WHERE `user`='$_GET[user]' LIMIT 1"); $userstats = mysql_fetch_array($resulta); $age = $userstats['age']; $sex = $userstats['sex']; $sexpref = $userstats['sexpref']; $maritalstatus = $userstats['maritalstatus']; $location = $userstats['location']; $lookingfor = $userstats['lookingfor']; $children = $userstats['children']; $smoking = $userstats['smoking']; $drinking = $userstats['drinking']; $lastlog = $userstats['lastlog']; $profileimage = $userstats['profileimagelocation']; //echo $age; $resultb = mysql_query("SELECT `interests` FROM `interests` WHERE `user`='$_GET[user]' LIMIT 1"); $userinterests = mysql_fetch_array($resultb); $interests = $userinterests['interests']; //echo $interests; $resultc = mysql_query("SELECT `aboutme` FROM `aboutme` WHERE `user`='$_GET[user]' LIMIT 1"); $useraboutme = mysql_fetch_array($resultc); $aboutme = $useraboutme['aboutme']; //echo $aboutme; $resultd = mysql_query("SELECT `fetishes` FROM `fetishes` WHERE `user`='$_GET[user]' LIMIT 1"); $userfetishes = mysql_fetch_array($resultd); $fetishes = $userfetishes['fetishes']; //echo $fetishes; //removes the resource and frees the database so it doesn't consume extra memory mysql_free_result($result); mysql_free_result($resulta); mysql_free_result($resultb); mysql_free_result($resultc); mysql_free_result($resultd); } else { ini_set('display_errors',1); error_reporting(E_ALL); //Get userid from the users table where the username matches the session username $result = mysql_query("SELECT `userid` FROM `user` WHERE `username`='$_SESSION[username]' LIMIT 1") or die("query failed 1".mysql_error()); //returns the results from the mysql database in an associative array format $profileusername = mysql_fetch_assoc($result); // RE assigns $profileusername value to $profileID $profileID = $profileusername['userid']; $username = $_SESSION['username']; //echo $username; //echo $profileID; $resulta = mysql_query("SELECT `age`,`sex`,`sexpref`,`maritalstatus`,`location`,`lookingfor`,`children`,`smoking`,`drinking`,`lastlog`,`profileimagelocation` FROM `profiledata` WHERE `username`='$_SESSION[username]'") or die("query failed 2".mysql_error()); $userstats = mysql_fetch_array($resulta); $age = $userstats['age']; $sex = $userstats['sex']; $sexpref = $userstats['sexpref']; $maritalstatus = $userstats['maritalstatus']; $location = $userstats['location']; $lookingfor = $userstats['lookingfor']; $children = $userstats['children']; $smoking = $userstats['smoking']; $drinking = $userstats['drinking']; $lastlog = $userstats['lastlog']; $profileimage = $userstats['profileimagelocation']; //echo $age; $resultb = mysql_query("SELECT `interests` FROM `interests` WHERE `username`='$_SESSION[username]'") or die("query failed 3".mysql_error()); $userinterests = mysql_fetch_array($resultb); $interests = $userinterests['interests']; //echo $interests; $resultc = mysql_query("SELECT `aboutme` FROM `aboutme` WHERE `username`='$_SESSION[username]'") or die("query failed 4".mysql_error()); $useraboutme = mysql_fetch_array($resultc); $aboutme = $useraboutme['aboutme']; $resultd = mysql_query("SELECT `fetishes` FROM `fetishes` WHERE `username`='$_SESSION[username]'") or die("query failed 5".mysql_error()); $userfetishes = mysql_fetch_array($resultd); $fetishes = $userfetishes['fetishes']; //echo $fetishes; //removes the resource and frees the database so it doesn't consume extra memory mysql_free_result($result); mysql_free_result($resulta); mysql_free_result($resultb); mysql_free_result($resultc); mysql_free_result($resultd); } ?> Quote Link to comment Share on other sites More sharing options...
Solution QuickOldCar Posted November 20, 2013 Solution Share Posted November 20, 2013 You use $_GET['user']; , so that would be http://site.com/script.php?user=their_name Have no idea your url location. Quote Link to comment Share on other sites More sharing options...
Jayden_Blade Posted November 20, 2013 Author Share Posted November 20, 2013 (edited) GOT IT!!!!!!!!! thanks for the help! Edited November 20, 2013 by Jayden_Blade Quote Link to comment 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.