I am trying to retrieve the primary key that I stored in a session but I can't find a way to print it.
Here is my controller code
$usr_result = $this->Judge_Model->get_user($username, $password);
if ($usr_result > 0)
{
//setting the session variables
$sessiondata = array('login' => TRUE,'JudgeName' => $username,'uid' => $uresult[0]->JudgeID);
$sessiondata = array($this->session->set_userdata($sessiondata));
redirect("JudgingApp/MainMenu");
My model
function get_user($usr, $pwd)
{
$sql = "select * from Judge where JudgeName = '" . $usr . "' and JudgePass = '" . $pwd . "' ''";
$query = $this->db->query($sql);
return $query->num_rows();
}
and the page that I want to print it on
public function MainMenu()
{
$data['Poster'] = $this->Judge_Model->get_Posters();
$this->load->view('JudgingApp/MainMenu',$data);
if (isset($this->session->userdata['JudgeName']))
{
echo $this->session->userdata['JudgeName'];
echo $this->session->userdata['uid'];
echo $this->session->userdata['Pass'];
}
else
{
echo nothing;
}
}
I just want to print for debugging purposes and ensure that the value is being passed not so much that I want to show the user their ID. I need the PK for another function so I need to make sure I can access it.
Try this
In Controller
$usr_result = $this->Judge_Model->get_user($username, $password);
if (!empty($usr_result))
{
$sessiondata = array(
'login' => TRUE,
'JudgeName' => $username,
'uid' => $uresult[0]['JudgeID']
);
if (!$this->session->set_userdata($sessiondata)) {
echo "Failed to set session";
} else {
redirect("JudgingApp/MainMenu");
}
}
else
{
echo "No Data Found";
}
public function MainMenu()
{
$data['Poster'] = $this->Judge_Model->get_Posters();
if (isset($this->session->userdata['JudgeName']))
{
# To print this on view you need to add this in view. Not in controller. Or Bind it to $data and pass it
echo $this->session->userdata['JudgeName'];
echo $this->session->userdata['uid'];
echo $this->session->userdata['Pass'];
}
else
{
echo nothing;
}
$this->load->view('JudgingApp/MainMenu',$data);
}
In Model
function get_user($username, $password)
{
$array = array('JudgeName' => $username, 'JudgePass' => $password);
$this->db->where($array);
$query = $this->db->get('Judge');
$result = $query->result_array();
return $result;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.