Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts

    User information using session to match username

    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.

    PHP Code:
      <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>

  • #2
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    $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']."'");
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    61
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hello,

    thank you, its working.
    Last edited by pagedrop; 02-03-2010 at 05:38 PM.

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    quick tip for you,
    instead this: <? echo $_SESSION['username'] ?>

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

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by angst View Post
    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:
    PHP Code:
    $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.

    Edit:
    Oops, sorry my bad. I thought you said it was not working. Ignore the babblings of the insane
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    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

  • #7
    Regular Coder hinch's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    923
    Thanks
    25
    Thanked 80 Times in 80 Posts
    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
    A programmer is just a tool which converts caffeine into code

    My work: http://www.fcsoftware.co.uk && http://www.firstcontactcrm.com
    My hobby: http://www.angel-computers.co.uk
    My life: http://www.furious-angels.com

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by angst View Post
    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
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    hmm, I've never run into this issue. and better performance hu? I'll have to look into this, thanks!

  • #10
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Quote Originally Posted by hinch View Post
    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...

  • #11
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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.

  • #12
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •