...

View Full Version : User information using session to match username



pagedrop
02-03-2010, 06:20 PM
Hi,

I'm having problem with getting information about a user from my mysql database. i have list of users with the fields, id, email, username, etc...

in my current php page, i have <? echo $seesion username...?> where i get the username of the current session, [this page is a subpage of my main website] thus i could show the username name, as welcome to your account ?username? something like that.

Now, i would like to show, your username: something, your email: something, last accessed etc.: something details.

I know, i can say, pull record, WHERE username=$_Session(username), so i can show only that particular record information.

At this point, it is showing the first record for all users information. i tried to do the above, but i am not able to do wat i want.

please suggest or help, thank you in advance.


<div class="fullContainer" style="height: 100%">
<table border="0">
<tr>
<td height="100%" valign="top" colspan="2">
<div id="title">
<h1 style="text-align: left">Welcome, <? echo $_SESSION['username'] ?></h1>
<h2 style="text-align: left">Edit your profile, Update your user info etc...</h2>
</div></td>
</tr>
<tr>
<td height="215" valign="top">

<p>
<div id="status" style="display: none;">
<?
if($_GET['success'] == "false")
{
echo "<p>Username either invalid or already exists.</p>";
}
?>
</div>

<div id="register_form" style="width: 495px">
<form class="add_form" enctype='multipart/form-data' action='#' method='post'>
<div class="container username"><div class="container_inner"><label class="title">Yourname</label>
<p> <?php
$result = mysql_query("SELECT firstname FROM sd_users");
$row = mysql_fetch_array( $result );
{
echo $row['firstname'];
}
?></p>
</div></div>
<div class="container email"><div class="container_inner"><label class="title">Email</label>
<p> <?php
$result = mysql_query("SELECT Email FROM sd_users WHERE username=$_SESSION['username']");
$row = mysql_fetch_array( $result );
{
echo $row['Email'];
}
?></p>
</div></div>
<div class="container password1"><div class="container_inner"><label class="title">Password</label>
<p>Keep it Secret
</p></div></div>
<div class="container username"><div class="container_inner"><label class="title">Member Since</label>
<p><?php
$result = mysql_query("SELECT signupdate FROM sd_users");
while($row = mysql_fetch_array( $result )) {
echo $row['signupdate'];
}
?></p>
</div></div>
<div class="container country"><div class="container_inner"><label class="title">Total Storage</label>
<p> <?php
if(isset($_SESSION['frienddir']))
{
echo getUserSize($_SESSION['frienddir'], $uploaddir);
}
else
{
echo getUserSize($_SESSION['username'], $uploaddir);
}
?> stored so far !</p>
</div></div>
<div class="container activity"><div class="container_inner"><label class="title">Last Activity</label>
<p>Your last known activity: <?= date("F j",$newstamp) ?></p>
</div></div>
<div class="container meter"><div class="container_inner"><label class="title">Current Storagedrop Meter</label>
<p><iframe id="myframe" src="spark.php" scrolling="no" frameborder="0" marginwidth="0" marginheight="20" width="160" height="42" name="I1"></iframe></font>
</p>Status: <?php
$result = mysql_query("SELECT ipaddress, confirmed FROM sd_users");
$row = mysql_fetch_array( $result );
$ip = strtolower(str_replace(" ", "",$_SERVER['REMOTE_ADDR']));
if ($ip == $row['ipaddress']) {
print "<img src='img/accept.png'>";
mysql_query("UPDATE sd_users SET confirmed = 1 WHERE ipaddress = '$ip'");
}
else
{
print "<img src='img/reject.png'>";
mysql_query("UPDATE sd_users SET confirmed = 0 WHERE ipaddress = '$ip'");
}
?>
</div></div>
</form>
</div></p>
</td>

hinch
02-03-2010, 06:24 PM
$result = mysql_query("SELECT Email FROM sd_users WHERE username=$_SESSION['username']");

change to

$result = mysql_query("SELECT Email FROM sd_users WHERE username='".$_SESSION['username']."'");

pagedrop
02-03-2010, 06:36 PM
Hello,

thank you, its working.

angst
02-03-2010, 07:36 PM
quick tip for you,
instead this: <? echo $_SESSION['username'] ?>

can you shorten it like this: <?=$_SESSION['username']?>

Fou-Lu
02-03-2010, 07:50 PM
quick tip for you,
instead this: <? echo $_SESSION['username'] ?>

can you shorten it like this: <?=$_SESSION['username']?>

That works until you're first major product rolls out and it burns you. There is no guarentee that short_open_tags is enabled in a PHP environment. If anything, you should be expanding you're tags to: <?php echo $_SESSION['username'];?>.

Can you be more specific on not working? Errors triggered? Result not matching expected? Etc. I presume as well that you've made a call to session_start() to initialize the session management on this page?

If you suspect that SQL is to blame for the error, trigger a die to see:


$result = mysql_query("SELECT field FROM table") or die(mysql_error());

If the query fails to execute, it will trigger the die statement instead which will show the error causing it.


Oops, sorry my bad. I thought you said it was not working. Ignore the babblings of the insane :D

angst
02-03-2010, 07:54 PM
he said above that it was corrected.

also, Yes your correct. ofcourse thats assuming that he plans to distribute these scripts.
though every linux server I've setup in the last 5 years has short tags enabled by default.

any idea what distro has this disabled by default? I run Ubuntu and sometimes Redhat/Fedora

hinch
02-03-2010, 08:12 PM
standard debian installs have short tags disabled by default as do most shared hosting providers.

rule of thumb its always better to correctly open your tags fully <?php

Fou-Lu
02-03-2010, 08:14 PM
he said above that it was corrected.

also, Yes your correct. ofcourse thats assuming that he plans to distribute these scripts.
though every linux server I've setup in the last 5 years has short tags enabled by default.

any idea what distro has this disabled by default? I run Ubuntu and sometimes Redhat/Fedora

You probably missed me edit on the above ;)
Best I know, short_open_tags is enabled by default in php.ini; however, I'll double check the recommended ini to see if its recommended off. The issue I have with short tags is that its quite possible that the feature is disabled, and I could have prevented additional work by simply using full tags (which should have better performance anyway). I like to go around things before they can sneak up and bite me ;)

angst
02-03-2010, 08:18 PM
hmm, I've never run into this issue. and better performance hu? I'll have to look into this, thanks!

angst
02-03-2010, 08:21 PM
standard debian installs have short tags disabled by default as do most shared hosting providers.

rule of thumb its always better to correctly open your tags fully <?php

odd, I use debian/ubuntu. and my installs always have it enabled by default...:confused:

MattF
02-04-2010, 06:39 PM
It's pointless coding for a config which only *may* exist when there is one which you know *will* exist. Short tags is useful either for idleness or legacy code, nothing more.

JohnDubya
02-04-2010, 07:12 PM
If you would like your PHP scripts to be able to migrate more easily to PHP6, use only <?php echo , since the PHP short tags option is being deprecated. Otherwise, if you're not going to distribute your code, and you're not going to upgrade to PHP6, you could use short tags if you desire.

Personally, I've left the short tags in my old code alone for now, but in my new code, I am only using <?php echo , since we will all have to eventually. I like merging into new technology ASAP, so I don't have to beat myself to get used to it later.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum