Retrieving a username from MYSQL (??)

Deezi

I have a custom title
Nov 14, 2016
50
12
I want something like this:
vGaQDmP.png

I already have a login form, a session started, but no idea how to make username & rank appear, tried searching for a while, but can't find something that actually works..

So I was wondering if anyone here could help me..


Have a nice day:)

*Thread can be closed, I figured this out.

SOLUTION
So the solution was much more simple than I though, atleast for me.
in your login file where you start the "$_SESSION[' ']" you just need to add another session called

$_SESSION['uid'] = $row['uid'];

// Row is the MYSQL database row in which the username is located, is not uid for everyone it's whatever you called the MYSQL row where usernames are located, and you could also use a number if you want. $_SESSION['uid'] is the name of the session, which I do believe you can call whatever you want.

EdTDJkf.png

After adding this session, you really only have to add it to your page ( I added to sidebar )
<div id="username"><?php echo $_SESSION['uid']; ?></div>
<div id="rank"><p><i><?php echo $_SESSION['rank']; ?></i></p></div>

// I do believe the <div>'s are not needed, I just added them so I could edit positions and such with CSS.


Then you might see it disappearing, which is actually good in this case, because when I first did it I starting trying to edit everything, which is something I realised I didn't have to do. After editing everything, I thought I'd just relog, so that I could see if the login & registration was still working, which was working just fine, and when I logged in, as that started a new session with the new $_SESSION[' '] that I added to the login page, and it was working fine.

VuEL9ej.png

 
Last edited:

Deezi

I have a custom title
Nov 14, 2016
50
12
Please post your solution so that visitors in the future can see the answer.
Updated, not the best explanation though, but hopefully people can understand it :D

The solution is SELECT username, rank FROM foo WHERE id = $_SESSION['id']
Ye, it was a lot more simple than I made it out to be in my head

I think you must use foreach or while
Ye I tried while, but didn't work for some reason, but the way I posted above did, which was a lot simpler :_
 

Zaka

Programmer
Feb 9, 2012
471
121
You don't really need to save all data in a session, you can just retrieve it from the database whenever you need it, or save it to a variable which is only there at runtime instead of picked up and stored by the browser.
 

Users who are viewing this thread

Top