Jump to content

A better way to show user information?


Artsybetty

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


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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.