Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] yet another DB related problem
#1

[eluser]KrizzAngel[/eluser]
is this right on representing the query "select * from tblstudent where username = session"??
Quote: function upanel()
{
$this->db->where('username', $this->session->userdata('$ses'));
$data['un']= $this->db->get('tblstudent');
$data['list']=$this->db->get('tbltopic');
$this->load->view('userpanel', $data);
}

and also i dont know if my display result is right coz im getting blank result on that field. here it is:

Quote:Welcome <?php foreach($un->result() as $surname): ?>
<?php echo $surname->lastname; ?>
<?php endforeach; ?>

P.S. i have a working list of topic on same page which where i used the $data['list']=$this->db->get('tbltopic'); using the result pattern above.
#2

[eluser]JHackamack[/eluser]
Your first query is correct.

The second loop though is a little off, why not use the ->row() to just return one row, unless you want to have multiple names in the Welcome statement.
#3

[eluser]KrizzAngel[/eluser]
ok i got it working now and use row() to display result but what i did is change this
Quote:$this->session->userdata('$ses');
to
Quote:$this->input->post('username')
. i dunno why it doesnt retrieve the value from login function from controller if my code is like this:

Quote: function upanel()
{
$this->db->select('lastname');
$this->db->where('username', $this->session->userdata('$ses')); <--"using $this->input->post('username') make my code works"

$this->db->from('tblstudent');
$data['un']=$this->db->get();
$data['list']=$this->db->get('tbltopic');
$this->load->view('userpanel', $data);
}

function validate_credentials()
{
$this->load->model('users');
$query = $this->users->validate();

if($query) // if the user's credentials validated...
{
$ses = array(
'username' => $this->input->post('username'),
'is_logged_in' => true
);
$this->session->set_userdata('$ses');
$this->upanel();
}
else // incorrect username or password
{

$this->index();
}
#4

[eluser]JHackamack[/eluser]
AH, i see the problem
$this->session->userdata(’$ses’);

won't evaluate to the $ses variable because its in single quotes. The best way is to remove the quotes all together
$this->session->userdata($ses);

If you really want to use quotes, wrap $ses in "
$this->session->userdata("$ses");
#5

[eluser]KrizzAngel[/eluser]
cool, i didnt expect that single qoute is differ from none or double qoute XD.. tnx
#6

[eluser]KrizzAngel[/eluser]
oh wait i thought it was all working..

funny.. i got the name but theres an error on top saying "Message: Undefined variable: ses

Filename: controllers/mont.php

Line Number: 16" :'(

P.S. im uploading an IMG file coz to show the error more clearly.. cant post an IMG.
#7

[eluser]JHackamack[/eluser]
Is line 16 of your mont controller :
$ses = array(
‘username’ => $this->input->post(‘username’),
‘is_logged_in’ => true
);
$this->session->set_userdata(’$ses’);
$this->upanel();


Or is it something different?
#8

[eluser]KrizzAngel[/eluser]
no, the line 16 is
Quote: function upanel()
{
$this->db->select('lastname');
$this->db->where('username', $this->session->userdata($ses)); <-- this one
$this->db->from('tblstudent');
$data['un']=$this->db->get();
$data['list']=$this->db->get('tbltopic');
$this->load->view('userpanel', $data);
}
#9

[eluser]JHackamack[/eluser]
are you calling upanel() before you validate_credentials. If you do then your userdata isn't set.
#10

[eluser]KrizzAngel[/eluser]
nope. as you can see on my first post. after logging in i'm calling validate credentials before goin to upanel..




Theme © iAndrew 2016 - Forum software by © MyBB