Welcome Guest, Not a member yet? Register   Sign In
How can I get logged in profile information?
#1

[eluser]Zero-10[/eluser]
Hey everyone!

I gave up a month ago on my personal project which was using codeigniter to make a RPG (hobby) but I couldn't figure out how to display my profile info. I managed to create a login system using sessions as per tutorials, and can display information from the sessions table but not from the membership table.

I tried joining the session username with the member username but failed miserably. What can I do to make this work? I searched and searched and searched but could never find an answer.

If you could point me to the right direction I would really appreciate it! Thank you for your time Smile
#2

[eluser]theprodigy[/eluser]
how about storing the user's id in session, and just using that in a where clause in your queries:
Code:
$this->db->where('users.id',$this->session->userdata('user')->id);
#3

[eluser]Zero-10[/eluser]
[quote author="theprodigy" date="1308557689"]how about storing the user's id in session, and just using that in a where clause in your queries:
Code:
$this->db->where('users.id',$this->session->userdata('user')->id);
[/quote]

Thanks for that, but I'm afraid that adding a id won't help my case. I have called the model but it's not working, this is what I have so far:

Code:
function my_information($usern)
        {
            $this->db->join('users', 'users.username = sessions.username', 'left');
            $query = $this->db->get();

            return $query;
        }

I get this error:

Code:
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN `nx_users` ON `nx_users`.`username` = `nx_sessions`.`username`' at line 2

SELECT * LEFT JOIN `nx_users` ON `nx_users`.`username` = `nx_sessions`.`username`

Filename: /var/www/vhosts/localhost/httpdocs/models/users_model.php

Line Number: 60

Line 60 is:
Code:
$query = $this->db->get();
#4

[eluser]theprodigy[/eluser]
you don't have a FROM line in your sql.
#5

[eluser]Zero-10[/eluser]
[quote author="theprodigy" date="1308560610"]you don't have a FROM line in your sql.[/quote]

Of course! lol Blush

Anywhoo, I did it a lot more simple than to join. What I did is that I defined the username from the session and then passed it over to my model which grabbed all the info needed and in my view file I did...

Code:
<?php foreach ($userinfo->result_array() as $row): ?>
&lt;? echo $row["username"]; ?&gt;<br/>
&lt;? echo $row["first_name"]; ?&gt; <br/>
&lt;? echo $row["last_name"]; ?&gt; <br/>
etc...
&lt;? endforeach; ?&gt;

And it pulls the data just fine :3 It's thanks to your FROM comment that triggered all of this haha because I did forget that in my earlier code. Thanks again!

EDIT: If this is poor practice to output data like this, please let me know. I know very little about security and even though I am doing this out of interest, I would prefer knowing whether or not I'm doing it correctly as i know my method requires database table names in the html file "last_name" for example.
#6

[eluser]skunkbad[/eluser]
There are a few established authentication libraries that would be easy to use and most are pretty robust compared to what you probably need. I've used DX Auth, and of course my own Community Auth. I've heard a lot of people in this forum recommend Ion Auth, Tank Auth, and I think the list goes on. Check the wiki!
#7

[eluser]Zero-10[/eluser]
Thank you skunkbad! I will study your suggested list Smile




Theme © iAndrew 2016 - Forum software by © MyBB