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 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;"; 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. 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']; 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 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 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'] ?> 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? 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? 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. 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 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 ";" 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. Link to comment https://forums.phpfreaks.com/topic/102423-solved-user-profiles/#findComment-524539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.