My problem is my data are being fetched at once, all of them. I need to view each user's data when Im on different logged in user. For example: For user1 I need to have Product1 and user2 I need to have Product2 but right now all Im getting is I can fetch all user's data.
here is my Model
As you can see I added my join query but still fetching all my data
public function showAllReviewers(){
$this->db->join('teachers', 'teachers.id = reviewers.user_id');
$query = $this->db->get('reviewers');
if($query->num_rows() > 0){
return $query->result();
}else{
return false;
}
}
My Controller
public function showAllReviewers()
{
$result = $this->reviewer_model->showAllReviewers();
echo json_encode($result);
}
My View
<tbody id="showdata">
</tbody>
I'm using ajax/js to fetch my data so here is my ajax/js script for additional info
//function
function showAllReviewers(){
$.ajax({
type: 'ajax',
url: '<?php echo base_url() ?>reviewers/showAllReviewers',
async: false,
dataType: 'json',
success: function(data){
var html = '';
var i;
for(i=0; i<data.length; i++){
html +='<tr class="table-info">'+
'<td>'+data[i].subject+'</td>'+
'<td>'+data[i].category+'</td>'+
'<td>'+data[i].set_rev+'</td>'+
'<td>'+data[i].group_name+'</td>'+
'<td>'+
' <span class="iconify" data-icon="bx:bx-edit" data-inline="false"></span> '+
' <span class="iconify" data-icon="bx:bx-trash" data-inline="false"></span> '+
'</td>'+
'</tr>';
}
$('#showdata').html(html);
},
error: function(){
alert('Could not get Data from Database');
}
});
}
EDIT: Login Controller
// Log in teacher
public function login(){
$this->form_validation->set_rules('code', 'Code', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('teachers/login');
$this->load->view('templates/footer');
} else {
// Get code
$code = $this->input->post('code');
// Get and encrypt the password
$password = $this->input->post('password');
// Login user
$user = $this->teacher_model->login($code, $password);
if($user){
// Create session
$user_data = array(
'user_id' => $user->id,
'name' => $user->name,
'code' => $code,
'logged_in' => true
);
$this->session->set_userdata($user_data);
redirect('teacher/home');
} else {
redirect('teachers/login');
}
}
}
Well, you can store user data like id etc in session when user logs in, like below in your controller:
$this->session->set_userdata('user_details', $user_data); // say user_details is the key we store it in
In your model, you can do like below:
<?php
public function showAllReviewers(){
$this->db->join('teachers', 'teachers.id = reviewers.user_id');
$this->db->where('reviewers.user_id',$this->session->userdata('user_details')['user_id']);
$query = $this->db->get('reviewers');
if($query->num_rows() > 0){
return $query->result();
}else{
return false;
}
}
Or an even better approach is to have a private variable say user_id and set the value in the constructor. This would make sure that whenever you are accessing model instance in your controller, you already have it in your model instead of retrieving from session always.
<?php
class YourModel extends CI_Model{
private $user_id;
function __construct(){
$this->user_id = $this->session->userdata('user_details')['user_id'];
}
public function showAllReviewers(){
$this->db->join('teachers', 'teachers.id = reviewers.user_id');
$this->db->where('reviewers.user_id',$this->user_id);
$query = $this->db->get('reviewers');
if($query->num_rows() > 0){
return $query->result();
}else{
return false;
}
}
}
You must add a where condition in showAllReviewers() function's Sql query by passing current logged in User/Teacher Id Or in case of CI you can fetch the same using isLogged/getId function which used to be present in system/library/customer.
Related
I made a user table that will link to his postings when he submits a post. (It parts works correctly)
So I have been trying to create a method in codeigniter 3. I have it set to where if the user is logged in and clicks his user name it will show all his submissions, by simply pulling from the table his user_id and then looping through his posts.
Well, I have two issues
when I enter in the url to call this function it wants a value for the uri. Example: localhost/CI/controller/account yet it will not load until I put something after account (account is the method name).
Like localhost/CI/controller/account/9
Also this function does not seem to work either for some reason, I do not know if it has something to do with it wanting another value.
I have researched this for the past hour with no luck.
Controller:
public function account(){
$data['title'] = 'Your submissions';
$data['posts'] = $this->post_model->user_posts();
$this->load->view('templates/header');
$this->load->view('users/profile', $data);
$this->load->view('templates/footer');
}
//view function the post by clicking on title
public function view ($slug=NULL){
$data['post'] = $this->post_model->get_posts($slug);
$post_id = $data['post']['id'];
$data['comments'] = $this->comment_model->get_comments($slug);
if(empty($data['post'])){
show_404();
}
$data['title'] = $data['post']['title'];
$this->load->view('templates/header');
$this->load->view('posts/view', $data);
$this->load->view('templates/footer');
}
Model:
public function user_posts (){
$usernum = $this->session->userdata('customer_id');
$this->db->order_by('created_time','DESC');
$query = $this->db->get_where('posts',array('customer_id ='=>'$usernum'));
return $query->result_array();
}
$query = $this->db->get_where('posts',array('slug'=>$slug));
return $query->row_array();
}
View:
<?php
echo $title;
foreach ($posts as $post): {
echo $post['title'];
}endforeach;
?>
Controller :
public function account($acno = "") {//changes
$data['title'] = 'Your submissions';
$data['posts'] = $this->Post_model->user_posts();//changes
echo'<pre>';print_r($data);die;//changes
$this->load->view('templates/header');
$this->load->view('users/profile', $data);
$this->load->view('templates/footer');
}
Model :
public function user_posts() {
$usernum = $this->session->userdata('customer_id');
$this->db->order_by('created_time', 'DESC');
$query = $this->db->get_where('posts', array('customer_id =' => $usernum));//changes
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return array();
}
}
Change model function like this
public function user_posts (){
$usernum = $this->session->userdata('customer_id');
$this->db->order_by('created_time','DESC');
$query = $this->db->get_where('posts', array('customer_id' => $usernum));
return $query->result_array();
}
The associative array does not need = in where() or get_where() to get the record
Do not need single quotes with $usernum
After trying somethings this is what corrected my issues
Public function user_posts (){
$this->db->order_by('created_time','DESC');
$query = $this->db->get_where('posts', array('customer_id' => $this->session->userdata('customer_id')));
return $query->result_array();
}
I believe by removing the $usernum = $this->session->userdata('customer_id'); and adding it to the query, now allows the user to call his own session id without the need to enter one into the function.
Thanks to those that gave me input
I dont know how your button click is set up but this is how you should do it.
Button click page
<?= site_url(); ?>controller_name/account
account function in controller
function account(){
//1. Check if user is Logged in
if (!$this->ion_auth->logged_in())
{
//If they are not logged in, redirect them to login page or do something
}
else{
//User is logged in so get submissions
//Get all submissions
$data['title'] = 'Your submissions';
$this->data['posts']= $this->post_model->user_posts();
$this->load->view('templates/header');
$this->load->view('users/profile', $data);
$this->load->view('templates/footer');
}}
User posts function in Model
function user_posts (){
$user = $this->ion_auth->user()->row();
$ref_id=$user->id; //Gets you user id
$this->db->where(['customer_id'=>$ref_id]);
$this->db->order_by('created_time','DESC');
$query=$this->db->get('posts');
if($query->result())
{
return $query->result();
}
else
{
return false;
}}
Also, consider using Ion Auth for your login in codeigniter as it allows you access session data easily without issues as the one you've been facing.
Hi guys I have a User controller and User_model model. I want to be able to retrieve and display a logged in users email and phone number from the database to a view after the user is logged in. any idea how I could go about this would be appreciated and if codes could be written to demonstrate I would be very happy.
MODEL
public function login($username, $password){
//validation
$this->db->select('id, email, username');
$this->db->where('username', $username);
$this->db->where('password', $password);
$this->db->where('status', 1);
$result = $this->db->get('users');
if($result->num_rows() == 1){
return $result->row(0)->id;
} else {
return FALSE;
}
}
public function get_user($username){
$this->db->where('username', $username);
$query = $this->db->get('users');
return $query->result();
}
CONTROLLER:
public function login(){
$data['title'] = 'Login';
$this->form_validation-> set_rules('username', 'Username', 'required');
$this->form_validation-> set_rules('password', 'Password', 'required');
if($this->form_validation->run() === FALSE){
$this->load->view('templates/header');
$this->load->view('users/login', $data);
$this->load->view('templates/footer');
} else {
// fetching user
$username = $this->input->post('username');
//Encrypted password
$password = md5($this->input->post('password'));
//login user
$user_id = $this->user_model->login($username, $password);
if($user_id){
//creating session
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => TRUE,
);
$this->session->set_userdata('user_data',$user_data);
// Set message to be sent
$this->session->set_flashdata('user_login', 'Welcome');
redirect('posts');
} else {
// Set message to be sent
$this->session->set_flashdata('login_fail', 'Login Failed');
redirect('users/login');
}
}
}
public function get_user()
{
if($this->session->userdata('logged_in')){
$username = $this->session->userdata('username');
$data['results'] = $this->user_model->get_user($username);
$this->load->view('templates/header');
$this->load->view('users/login', $data);
$this->load->view('templates/footer');
}
}
There is basic problem in your Controller
Session Data Problem: In your Controller you storing all array data in CodeIgniter Session:
the 'user_data' would work like array key, and all other array will be assign as keys data;
$this->session->set_userdata('user_data', $user_data);
and you retrieving/checking the session data by using $this->session->userdata('logged_in') and $this->session->userdata('username'), It's wrong my friend. You can get user data session by $this->session->userdata('user_data')['username'] or $this->session->userdata['user_data']['username'] ...
Because the session would be like;
Array
(
[__ci_last_regenerate] => 1499791562
// This is the array key 'user_data' where your array data stores
[user_data] => Array
(
[user_id] => 1
[username] => scott
[email] => scott.dimon#example.com
[phone_number] => 1234567890
[first_name] => Scott
[logged_in] => 1
)
)
So, you have to have use 'user_data' with session to get your data
One thing I would like to share with everyone, Always Read The Docs and manual Carefully. Believe me if you read before the start, your code would be more nicer and cleaner... Ha ha ha ha ha.. ;) :|
When you login if you set the users_id in session you can get the information like
Read manual also
https://www.codeigniter.com/user_guide/database/results.html#result-rows
https://www.codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view
Make sure you autoload session, and database.
Examples ONLY below.
Filename: User_model.php
class User_model extends CI_Model {
public function get_user($id)
{
$this->db->where('user_id', $id);
$user_query = $this->db->get('yourtable');
return $user_query->row_array();
}
}
Filename: Dashboard.php
Controller
<?php
class Dashboard extends CI_Controller {
public function __construct()
{
parent::__construct();
if (!$this->session->userdata('user_id'))
{
redirect('logoutcontroller');
}
$this->load->model('user_model');
}
public function index()
{
$userdata = $this->user_model->get_user($this->session->userdata('user_id'));
/** You can use what you want example
$data['email'] = $userdata['email'];
**/
$data['username'] = $userdata['username'];
$this->load->view('some_view', $data);
}
}
View
<?php echo $username;?>
You can use session to carry the logged in user detail.
This is your model code:
//In your model
$query = $this->db
->select('id,email,phone')
->where(['username' => $username, 'password' => $password])
->where('status','1')
->get('users');
$user_data = $query->row_array();
if (!empty($user_data)) {
return $user_data;
} else {
return FALSE;
}
In side the controller where you get the user data if username & password is correct. Here you can put the user data on session:
//In Side Controller
$user_data = $this->user_model->login($username, $password);
if(isset($user_data) && !empty($user_data)){
// you can directly add the `$user_data` to the session as given billow.
// set user data in session
$this->session->set_userdata('user_data', $user_data);
Now after putting a data on session you can retrive it any where, on any view or in side morel, controller.
//retrive the user data in any view
//To echo in view Inside your view code.
<?php
$session_data = $this->session->userdata('user_data');
$user_email = $session_data['email'];
$user_phone = $session_data['phone'];
$user_id = $session_data['id'];
?>
<?= $user_phone ?> OR <?php echo $user_phone; ?>
<?= $user_email ?> OR <?php echo $user_email; ?>
On Your $this->load->view('users/login', $data); this view. Where the HTML & PHP code placed.
Example:
<html>
// Your View Page
</body>
<?php
$session_data = $this->session->userdata('user_data');
$user_email = $session_data['email'];
$user_phone = $session_data['phone'];
$user_id = $session_data['id'];
?>
<h1> Logged In User Email: <?= $user_email ?> </h1>
<h1> Logged In User Phone: <?= $user_phone ?> </h1>
<body>
</html>
Note: Once You save the user data inside the session then you don't need to pass that data to the view form controller. You just need to echo it where you need that.
You need to load session library first. like
$this->load->library('session');
Then after you can save your data into session like,
$newdata = array(
'username' => 'johndoe',
'email' => 'johndoe#some-site.com',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
Then where ever you require at controller you can retrive session data like,
$data['session_data'] = $this->session->all_userdata();
and then pass to your view,
$this->load->view('data', $data);
and then access that data into your view with the key,
<?= $session_data['username']; ?>
I hope it helps,
Does this answer your question?
public function login($username, $password){
$db = $this->db;
//validation
$db->select('id, email, username');
$db->where('username', $username);
$db->where('password', $password);
$db->where('status', 1);
$result = $db->get('users')->row_array();
return empty($result['id']) ? false : $result['id'];
}
With a unique index on username you won't need to check the number of rows as it will be limited to 1.
if($user_id){
//creating session
$user_data = array(
'user_id' => $user_id,
'username' => $username,
'logged_in' => TRUE,
);
$this->session->set_userdata($user_data);
// Set message to be sent
$data['session_data'] = $this->session->all_userdata();
$this->session->set_flashdata('user_login', 'Welcome');
$this->load->view('posts', $data);
//redirect('posts');
}
else {
// Set message to be sent
$this->session->set_flashdata('login_fail', 'Login Failed');
redirect('users/login');
}
}
at the view,
<?php print_r($session_data); ?>
if you get your session data into print,
you can display it like,
<?= $session_data['user_id']; ?>
****Modal**
//user login**
function userlogin($data)
{
$condition = "username =" . "'" . $data['username'] . "' AND " . "password =" . "'" . $data['password'] . "' AND " . "status = '1'";
$this->db->select("*");
$this->db->from("user");
$this->db->where($condition);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1)
{
return $query->result();
}
else {
return false;
}
}
And in your Controller check
if($this->modal_name->login()==false)
{
//redirect user to login page
}
else
{
$data['details'] = $this->modal_name->login();
$this->load->view("post",$data);
}
View
foreach($details as $detail)
{
echo $detail->id;
echo $detail->username;
}
Model
function Updateno($user,$data){
$this->db->where('username', $user);
$this->db->update('user', $data);
}
Controller
//user login function
function Ulogin(){
if($this->session->userdata('user'))
{
$data['user'] = $this->session->userdata('user');
$this->load->view("User/choosecategory",$data);
}
else
{
$data = array(
'username' =>$this->input->post('username'),
'password' =>$this->input->post('password'),
);
$this->form_validation->set_rules('username','UserName','required');
$this->form_validation->set_rules('password','Password','required');
if($this->form_validation->run()==false)
{
$this->load->view('User/login');
}
else
{
if($this->user_model->userlogin($data)==false)
{
$data['error'] = '<div class="alert alert-danger text-danger">Please Provide Valid Username/Password!</div>';
$this->load->view('User/login',$data);
}
else
{
$this->session->set_userdata('user',$data['username']);
$data['user'] = $this->session->userdata('user');
$counter = array(
'logged_in' =>'logged_in'+1
);
$this->user_model->Updateno($this->session->userdata('user'),$counter);
$this->load->view("User/choosecategory",$data);
}
}
}
}
I want whenever user login successfully my logged_in cloumn value increase by 1 but in this code the value of logged_in column always to 1,plz help me anyone here
the only thing you need to do here is to increment the value by 1
try the following piece of code
your model
function Updateno($user)
{
$this->db->where('username', $user);
$this->db->set("logged_in","logged_in+1",false);
$this->db->update('user');
}
and in your controller
$this->user_model->Updateno($this->session->userdata('user'));
What you want to do is this:
$value = explode("logged_in", $counter['logged_in']); //get the number of the counter
$counter['logged_in'] = 'logged_in' . ((int)$value[1] +1); //increase value by 1
This will get the current counter value from your string and increase it by 1
I made a demo to show how you can use it
DEMO: https://eval.in/773121
I've been encountering problems with passing variables form different views. What i want is whenever a user logs in his id, It would automatically retrieve the data that is connected to that ID from the database.
Apparently, I have 3 controllers for my login (c_home,c_login and c_verifylogin), 1 model (m_login) and 1 view (v_home)
Can anyone tell me what I am missing?
Controllers:
c_login
function index() {
$this->load->helper(array('form','html'));
$this->load->view('v_login'); //load view for login
}
c_home
function index() {
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['studentid'] = $session_data['studentid'];
$this->load->view('v_display', $data);
} else {
//If no session, redirect to login page
redirect('c_login', 'refresh');
}
}
function getGrades() {
$data['query'] = $this->m_login->result_getGrades();
$this->load->view('v_display', $data);
}
function logout() {
//remove all session data
$this->session->unset_userdata('logged_in');
$this->session->sess_destroy();
redirect('c_login', 'refresh');
}
c_verifylogin
function index() {
$this->form_validation->set_rules('studentid', 'studentid', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'password', 'trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE) {
$this->load->view('v_login');
} else {
//Go to private area
redirect('c_home', 'refresh');
}
}
function check_database() {
//Field validation succeeded. Validate against database
$studentid = $this->input->post('studentid');
$password = $this->input->post('password');
//query the database
$result = $this->login->login($studentid, $password);
if($result) {
$sess_array = array();
foreach($result as $row) {
//create the session
$sess_array = array('studentid' => $row->studentid);
//set session with value from database
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
} else {
//if form validate false
$this->form_validation->set_message('check_database', 'Invalid username or password');
return FALSE;
}
}
m_login
function login($studentid, $password)
{
//create query to connect user login database
$this->db->select('studentid, password');
$this->db->from('users');
$this->db->where('studentid', $studentid);
$this->db->where('password', md5($password));
$this->db->limit(1);
//get query and processing
$query = $this->db->get();
if($query->num_rows() == 1) {
return $query->result(); //if data is true
} else {
return false; //if data is wrong
}
}
function result_getGrades()
{
$this->db->select('grades.blockcode,subjectblocking.subjectcode,subjects.description,grades.final');
$this->db->from('grades');
$this->db->join('subjectblocking','grades.blockcode=subjectblocking.blockcode');
$this->db->join('subjects','subjectblocking.subjectcode=subjects.subjectcode');
$this->db->where('studentid', '2013-F0218');
$this->db->where('sem', '1');
$this->db->where('sy','2013-2014');
$query=$this->db->get();
return $query->result();
}
Views: v_display
<!DOCTYPE html>
<head>
<title>Simple Login with CodeIgniter - Private Area</title>
</head>
<body>
<h1>Home</h1>
<h2>Welcome <?php echo $studentid; ?>!</h2>
Logout
<table class="table">
<thead>
<th>Subject Code</th>
<th>Description</th>
<th>Grade</th>
</thead>
<?php foreach ($query as $row){ ?>
<tr>
<td><?php echo $row->subjectcode;?><br></td>
<td><?php echo $row->description;?><br></td>
<td><?php echo $row->final;?><br></td>
</tr>
<?php } ?>
</table>
</body>
</html>
and the error that i have encountered is
Message: Undefined variable: query
and
Message: Invalid argument supplied for foreach()
The first thing I see is, that you don't name the table in your query:
Change:
$query = $this->db->get();
To this:
$query = $this->db->get("your_table_name_here);
When I read your code I feel headache.
You can actually just put the verify login in your c_login and not create another c_verify controller.
To make it sense
Try to refactor your code like the connection will be like this
c_home = private page that can only be access if the user is login
c_login = verify if the input of user passed and check the data from database.
To summarize
c_login will compose of this functions :
verify user input
check database through m_login
Note: Your logout should be put in the core so that all controller can use it
In your c_home, you just need to create a model that will get the data from database and pass it to your
$data['grades'] = $your_model->get_grades
the variable grades will now be pass to view using $data.
Note: You don't need to create another function to just get the data. What you only need is the model because that is the purpose of model and just pass it in your variable in your controller.
https://www.codeigniter.com/userguide3/general/
Summarize :
From Model -> Controller -> View Get data from model pass it in
controller show it in view
I hope you're doing fine. Can somebody help me with my problem? I have 2 tables. The other one is for customers, it has an auto-increment value for customer_id. The other table is for orders, it has an auto-increment also for its orders_id and a foreign key from the other table (customers).
When I insert a new customer, if it is successful, I want the page to be redirected to the add new order page. In inserting new order, the customer_id field in my orders table should have the same value as the newly added customer. Adding customer and adding new order is of different function in my controller. I am having an error 1452 when inserting the new order, which means the value inserted for the foreign key customers_id in the orders table is different with the value in the other table (customers).
Now, I've got this solution using session. My problem is the other session for getting the last id is overriding the session for logging in.
Here's some code snippets from my controller:
Class MyController extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->c_id = 0;
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
if($session_data['username'] == 'administrator'){
$this->load->database('sample');
$this->load->model('samplemodel_model');
$this->load->library('form_validation');
} else {
redirect('home', 'refresh');
}
} else {
redirect('login', 'refresh');
}
}
public function index() {
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
//code for validation here
$customers = $this->samplemodel_model->get_entries('customers');
if($this->form_validation->run() == FALSE) {
//Field validation failed.
} else {
//Insert $data
//$data = array('xxxxxx');
//data is something like that
$this->create($data);
}
}
else
{
//If there's no session it will redirect to login page
}
}
//add new orders
public function addOrders() {
if($this->session->userdata('last_inserted_id')) //if I use this session, I can get the last inserted ID but the session data for the login will not be retrieved.
{
$session_data = $this->session->userdata('last_inserted_id');
$orders = $this->samplemodel_model->get_entries('orders');
if($this->form_validation->run() == FALSE) {
//Field validation failed.
} else {
//Insert data
$data = array('customer_id' => $session_data['customer_id'],
'order_type' => $this->input->post('order_type'));
$this->createItem($data);
}
}
else
{
//If no session, redirect to login page
redirect('login', 'refresh');
}
}
//create customer
public function create($data) {
//Insert data
$customers = $this->samplemodel_model->get_entries('customers');
//$data = array(xxxxx);
//somethin' like that for data array
$this->load->samplemodel_model->create('customers', $data);
//***********************************************************//
// get and save last id inserted //
//***********************************************************//
//query the database
$result = $this->samplemodel_model->get_last_inserted($this->db->insert_id());
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array('customer_id' => $row->customer_id);
$this->session->set_userdata('last_inserted_id', $sess_array);
}
return TRUE;
}
else
{
echo "<script type='text/javascript'>alert('error');</script>";
return false;
}
session_start('last_inserted_id');
//********************************************************//
// end //
//********************************************************//
redirect('myController/addOrders', 'refresh');
}
public function createItem($data) {
//Insert data
$orders = $this->samplemodel_model->get_entries('orders');
$data = array('customer_id' => $session_data['customer_id'],
'order_type' => $this->input->post('order_type'));
$this->load->samplemodel_model->create('orders', $data);
//I'm not so sure if it is in this function that I should place the unset for the session 'last_inserted_id'
redirect('home', 'refresh');
}
}
And in my model, I inserted another function which helps me saving the last id inserted. Here's it:
public function get_last_inserted($id)
{
$this -> db -> select('customer_id');
$this -> db -> from('customers');
$this -> db -> where('customer_id', $id);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
PLEEEASE! HELP :'( I would really appreciate if you have any other ideas. THANK YOU SOOOOO MUCH!
The issue is that you're redirecting, Each HTTP request is it's own process with it's own variables, and each request can't access the variables set in other requests.
Try passing the customer ID as a parameter to addOrders(), you can then use the codeigniter way of passing params around :
http://www.example.com/controller/method/paramter
Check the docs :
https://ellislab.com/codeigniter/user-guide/general/controllers.html
under the segment : Passing URI Segments to your Functions
Other possible solution : Store the customerID in the session, or in a user object you instantiate when you create a new user, but that's more dependent of the use case.