Artsybetty Posted March 31, 2013 Share Posted March 31, 2013 whats the best way to set session variables from db? i'm kinda new to this, so im just checking the session variable "uid" against the users id in the db, and if true, posting something, should i be doing this totally different? any help is apreciated $result = mysql_query("SELECT * FROM `users` WHERE `id`='".$_SESSION["uid"]."' LIMIT 1");while($row = mysql_fetch_array($result)){echo $row['username'];echo $row['id'];} Quote Link to comment https://forums.phpfreaks.com/topic/276353-a-better-way-to-show-user-information/ Share on other sites More sharing options...
Solution Barand Posted March 31, 2013 Solution Share Posted March 31, 2013 // define query in a string first, it makes debugging easier if there's an error // don't use *, define the columns to be selected $sql = "SELECT id, username FROM `users` WHERE `id`='{$_SESSION["uid"]}' LIMIT 1"; $result = mysql_query($sql); // you don't need a while loop for a single row if ($row = mysql_fetch_array($result)) { echo $row['username']; echo $row['id']; } Quote Link to comment https://forums.phpfreaks.com/topic/276353-a-better-way-to-show-user-information/#findComment-1422131 Share on other sites More sharing options...
Artsybetty Posted April 1, 2013 Author Share Posted April 1, 2013 cheers barand. Quote Link to comment https://forums.phpfreaks.com/topic/276353-a-better-way-to-show-user-information/#findComment-1422203 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.