Jump to content

A better way to show user information?


Go to solution Solved by Barand,

Recommended Posts

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'];
}

Link to comment
https://forums.phpfreaks.com/topic/276353-a-better-way-to-show-user-information/
Share on other sites

  • Solution

// 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'];
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.