DeanWhitehouse Posted April 22, 2008 Share Posted April 22, 2008 i have this code for the user profile link <a href='user_profile.php?id=<?php echo $_SESSION['user_id']; ?>'>Settings</a><br> now on the user_profile.php page how do i display this users profile, can i call all there details from the database using there user_id Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/ Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 yes. you would do something like this $user = addslashes($_GET['id']); $sql = "SELECT * FROM `table` WHERE `id`='{$user}' LIMIT 1;"; Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524506 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 $id = $_GET['id']; Then use a query like: SELECT * FROM users WHERE user_id='$id';  And display everything appropriately. Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524508 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Of course, you'd error check and type cast though: Â if (!isset($_GET['id']) { Â Â echo "Invalid user ID"; Â Â // Do any includes for like, footers or w/e. Â Â exit(); } $id =Â (int) $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524510 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 how would i arrange this data Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524511 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 <?php $user = addslashes($_GET['id']); $sql = "SELECT * FROM `table` WHERE `id`='{$user}' LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['username'] //etc, etc, etc Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524514 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 i get this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/deanwhitehouse.awardspace.co.uk/test/user_profile.php on line 9 Â with this code <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $user_id = addslashes($_GET['id']); $sql = "SELECT * FROM `$user` WHERE `id`='{$user_id}' LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name'] ?> Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524516 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 i get this error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/deanwhitehouse.awardspace.co.uk/test/user_profile.php on line 9 Â with this code <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $user_id = addslashes($_GET['id']); $sql = "SELECT * FROM `$user` WHERE `id`='{$user_id}' LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name'] ?> That was sample code. is your DB set up that way? Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524518 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 this code is right but, it doesn't display anything from the database <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $user_id = addslashes($_GET['id']); $sql = "SELECT * FROM `$user` WHERE `user_id`='{$user_id}' LIMIT 1;"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row['user_name'] ?> i tried changing it to this but, it still isn't displaying anything <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $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'] ?> do i need to echo it? Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524522 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 yup. also, you don't have session_start() at the top. Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524526 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 no, db_connect.php has the session_start() on it also when i try to echo like this <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $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'] echo "$username"; ?> Â i get an "unexpected" error with this, it doesn't expect the echo Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524531 Share on other sites More sharing options...
jonsjava Posted April 22, 2008 Share Posted April 22, 2008 <?php require_once 'db_connect.php'; require_once 'nav_bar.php'; require_once 'logged_in.php'; $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']; echo "$username"; ?> forgot a ";" Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524535 Share on other sites More sharing options...
DeanWhitehouse Posted April 22, 2008 Author Share Posted April 22, 2008 o yer, soz my fault, i thought i had tried it with that added. Thanks for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524539 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.