HOW to set_userdata login codeigniter












0















I get Message error: Trying to get property of non-object, and i dont know solved this problem. please help



CONTROLLER



public function login_user(){
$user =array( 'email_user'=> $this->input->post('email_user'),
'password_user'=> $this->input->post('password_user'));
$myquery= $this->user_model->login_check($user['email_user'],
$user['password_user']);
if ($myquery== TRUE) {
foreach($myquery as $d){
$session_array = array(
'id_user'=>$d->id_user,
'username_user'=>$d->username_user,
'email_user'=>$d->email_user,
'phone_user'=>$d->phone_user,
'tanggal_lahir'=>$d->tanggal_lahir
);
$this->session->set_userdata('loggedIn',$session_array);}
$this->load->view('v_formluar.php');
}
else{
$this->session->set_flashdata('error_msg', 'Error occured,Try again.');
$this->load->view('v_login.php');
}
}


I don't know to get data from model to controller,



MY MODEL



public function login_check($email, $password){

$this->db->select('registrasi.user_id,
registrasi.username_user,
registrasi.email_user,
registrasi.password_user')
->from('registrasi')
->where("registrasi.email_user = '$email' OR registrasi.username_user = '$email' ");

$query = $this->db->get();

if($query->num_rows() == 1){
return $query->row();
} else {
return false;
}
}









share|improve this question




















  • 1





    Can you please provide proper error message with line number

    – Abhijit
    Nov 13 '18 at 10:38











  • With the above model query, Are you getting the record?

    – Danish Ali
    Nov 13 '18 at 11:55
















0















I get Message error: Trying to get property of non-object, and i dont know solved this problem. please help



CONTROLLER



public function login_user(){
$user =array( 'email_user'=> $this->input->post('email_user'),
'password_user'=> $this->input->post('password_user'));
$myquery= $this->user_model->login_check($user['email_user'],
$user['password_user']);
if ($myquery== TRUE) {
foreach($myquery as $d){
$session_array = array(
'id_user'=>$d->id_user,
'username_user'=>$d->username_user,
'email_user'=>$d->email_user,
'phone_user'=>$d->phone_user,
'tanggal_lahir'=>$d->tanggal_lahir
);
$this->session->set_userdata('loggedIn',$session_array);}
$this->load->view('v_formluar.php');
}
else{
$this->session->set_flashdata('error_msg', 'Error occured,Try again.');
$this->load->view('v_login.php');
}
}


I don't know to get data from model to controller,



MY MODEL



public function login_check($email, $password){

$this->db->select('registrasi.user_id,
registrasi.username_user,
registrasi.email_user,
registrasi.password_user')
->from('registrasi')
->where("registrasi.email_user = '$email' OR registrasi.username_user = '$email' ");

$query = $this->db->get();

if($query->num_rows() == 1){
return $query->row();
} else {
return false;
}
}









share|improve this question




















  • 1





    Can you please provide proper error message with line number

    – Abhijit
    Nov 13 '18 at 10:38











  • With the above model query, Are you getting the record?

    – Danish Ali
    Nov 13 '18 at 11:55














0












0








0








I get Message error: Trying to get property of non-object, and i dont know solved this problem. please help



CONTROLLER



public function login_user(){
$user =array( 'email_user'=> $this->input->post('email_user'),
'password_user'=> $this->input->post('password_user'));
$myquery= $this->user_model->login_check($user['email_user'],
$user['password_user']);
if ($myquery== TRUE) {
foreach($myquery as $d){
$session_array = array(
'id_user'=>$d->id_user,
'username_user'=>$d->username_user,
'email_user'=>$d->email_user,
'phone_user'=>$d->phone_user,
'tanggal_lahir'=>$d->tanggal_lahir
);
$this->session->set_userdata('loggedIn',$session_array);}
$this->load->view('v_formluar.php');
}
else{
$this->session->set_flashdata('error_msg', 'Error occured,Try again.');
$this->load->view('v_login.php');
}
}


I don't know to get data from model to controller,



MY MODEL



public function login_check($email, $password){

$this->db->select('registrasi.user_id,
registrasi.username_user,
registrasi.email_user,
registrasi.password_user')
->from('registrasi')
->where("registrasi.email_user = '$email' OR registrasi.username_user = '$email' ");

$query = $this->db->get();

if($query->num_rows() == 1){
return $query->row();
} else {
return false;
}
}









share|improve this question
















I get Message error: Trying to get property of non-object, and i dont know solved this problem. please help



CONTROLLER



public function login_user(){
$user =array( 'email_user'=> $this->input->post('email_user'),
'password_user'=> $this->input->post('password_user'));
$myquery= $this->user_model->login_check($user['email_user'],
$user['password_user']);
if ($myquery== TRUE) {
foreach($myquery as $d){
$session_array = array(
'id_user'=>$d->id_user,
'username_user'=>$d->username_user,
'email_user'=>$d->email_user,
'phone_user'=>$d->phone_user,
'tanggal_lahir'=>$d->tanggal_lahir
);
$this->session->set_userdata('loggedIn',$session_array);}
$this->load->view('v_formluar.php');
}
else{
$this->session->set_flashdata('error_msg', 'Error occured,Try again.');
$this->load->view('v_login.php');
}
}


I don't know to get data from model to controller,



MY MODEL



public function login_check($email, $password){

$this->db->select('registrasi.user_id,
registrasi.username_user,
registrasi.email_user,
registrasi.password_user')
->from('registrasi')
->where("registrasi.email_user = '$email' OR registrasi.username_user = '$email' ");

$query = $this->db->get();

if($query->num_rows() == 1){
return $query->row();
} else {
return false;
}
}






php codeigniter login






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 10:53









RiggsFolly

71.8k1867113




71.8k1867113










asked Nov 13 '18 at 10:34









Vincent van goghVincent van gogh

1




1








  • 1





    Can you please provide proper error message with line number

    – Abhijit
    Nov 13 '18 at 10:38











  • With the above model query, Are you getting the record?

    – Danish Ali
    Nov 13 '18 at 11:55














  • 1





    Can you please provide proper error message with line number

    – Abhijit
    Nov 13 '18 at 10:38











  • With the above model query, Are you getting the record?

    – Danish Ali
    Nov 13 '18 at 11:55








1




1





Can you please provide proper error message with line number

– Abhijit
Nov 13 '18 at 10:38





Can you please provide proper error message with line number

– Abhijit
Nov 13 '18 at 10:38













With the above model query, Are you getting the record?

– Danish Ali
Nov 13 '18 at 11:55





With the above model query, Are you getting the record?

– Danish Ali
Nov 13 '18 at 11:55












4 Answers
4






active

oldest

votes


















0














Your use of $myquery is not correct since your model return data or false. Change the controller code as follows:



 public function login_user(){
$user =array( 'email_user'=> $this->input->post('email_user'),
'password_user'=> $this->input->post('password_user'));
$myquery= $this->user_model->login_check($user['email_user'],
$user['password_user']);
if ($myquery!=FALSE) {
foreach($myquery as $d){
$session_array = array(
'id_user'=>$d->id_user,
'username_user'=>$d->username_user,
'email_user'=>$d->email_user,
'phone_user'=>$d->phone_user,
'tanggal_lahir'=>$d->tanggal_lahir
);
$this->session->set_userdata('loggedIn',$session_array);}
$this->load->view('v_formluar.php');
}
else{
$this->session->set_flashdata('error_msg', 'Error occured,Try again.');
$this->load->view('v_login.php');
}
}





share|improve this answer































    0














    First you load the model in your controller:



    $this->load->model('your_model_name_m');


    Then you can use the model in your controller:



    $logged_in = $this->your_model_name_m->login_check('me@us.com', 'password!#$');


    If you frequently use this model, you can also autoload it via the config file in the model section:



    $autoload['model'] = array( "your_model_name" );





    share|improve this answer































      0














      Your Model



      Use brackets with your database condition



      public function login_check($email, $password){
      $this->db->select('registrasi.user_id,
      registrasi.username_user,
      registrasi.email_user,
      registrasi.password_user')
      ->from('registrasi')
      ->where("(registrasi.email_user = '$email' OR registrasi.username_user = '$email' )");

      $query = $this->db->get();
      if($query->num_rows() == 1){
      return $query->row();
      } else {
      return false;
      }
      }


      Your Controller



      if(isset($myquery) && $myquery != ''){
      //foreach loop
      }else{
      //No record found
      }


      You can also use where() and or_where() for your condition



      Read More






      share|improve this answer































        0














        Try by replacing



        if($myquery==TRUE){ 
        // your code
        }


        with



        if($myquery){ 
        // your code
        }





        share|improve this answer

























          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279053%2fhow-to-set-userdata-login-codeigniter%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Your use of $myquery is not correct since your model return data or false. Change the controller code as follows:



           public function login_user(){
          $user =array( 'email_user'=> $this->input->post('email_user'),
          'password_user'=> $this->input->post('password_user'));
          $myquery= $this->user_model->login_check($user['email_user'],
          $user['password_user']);
          if ($myquery!=FALSE) {
          foreach($myquery as $d){
          $session_array = array(
          'id_user'=>$d->id_user,
          'username_user'=>$d->username_user,
          'email_user'=>$d->email_user,
          'phone_user'=>$d->phone_user,
          'tanggal_lahir'=>$d->tanggal_lahir
          );
          $this->session->set_userdata('loggedIn',$session_array);}
          $this->load->view('v_formluar.php');
          }
          else{
          $this->session->set_flashdata('error_msg', 'Error occured,Try again.');
          $this->load->view('v_login.php');
          }
          }





          share|improve this answer




























            0














            Your use of $myquery is not correct since your model return data or false. Change the controller code as follows:



             public function login_user(){
            $user =array( 'email_user'=> $this->input->post('email_user'),
            'password_user'=> $this->input->post('password_user'));
            $myquery= $this->user_model->login_check($user['email_user'],
            $user['password_user']);
            if ($myquery!=FALSE) {
            foreach($myquery as $d){
            $session_array = array(
            'id_user'=>$d->id_user,
            'username_user'=>$d->username_user,
            'email_user'=>$d->email_user,
            'phone_user'=>$d->phone_user,
            'tanggal_lahir'=>$d->tanggal_lahir
            );
            $this->session->set_userdata('loggedIn',$session_array);}
            $this->load->view('v_formluar.php');
            }
            else{
            $this->session->set_flashdata('error_msg', 'Error occured,Try again.');
            $this->load->view('v_login.php');
            }
            }





            share|improve this answer


























              0












              0








              0







              Your use of $myquery is not correct since your model return data or false. Change the controller code as follows:



               public function login_user(){
              $user =array( 'email_user'=> $this->input->post('email_user'),
              'password_user'=> $this->input->post('password_user'));
              $myquery= $this->user_model->login_check($user['email_user'],
              $user['password_user']);
              if ($myquery!=FALSE) {
              foreach($myquery as $d){
              $session_array = array(
              'id_user'=>$d->id_user,
              'username_user'=>$d->username_user,
              'email_user'=>$d->email_user,
              'phone_user'=>$d->phone_user,
              'tanggal_lahir'=>$d->tanggal_lahir
              );
              $this->session->set_userdata('loggedIn',$session_array);}
              $this->load->view('v_formluar.php');
              }
              else{
              $this->session->set_flashdata('error_msg', 'Error occured,Try again.');
              $this->load->view('v_login.php');
              }
              }





              share|improve this answer













              Your use of $myquery is not correct since your model return data or false. Change the controller code as follows:



               public function login_user(){
              $user =array( 'email_user'=> $this->input->post('email_user'),
              'password_user'=> $this->input->post('password_user'));
              $myquery= $this->user_model->login_check($user['email_user'],
              $user['password_user']);
              if ($myquery!=FALSE) {
              foreach($myquery as $d){
              $session_array = array(
              'id_user'=>$d->id_user,
              'username_user'=>$d->username_user,
              'email_user'=>$d->email_user,
              'phone_user'=>$d->phone_user,
              'tanggal_lahir'=>$d->tanggal_lahir
              );
              $this->session->set_userdata('loggedIn',$session_array);}
              $this->load->view('v_formluar.php');
              }
              else{
              $this->session->set_flashdata('error_msg', 'Error occured,Try again.');
              $this->load->view('v_login.php');
              }
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 13 '18 at 10:52









              Osama IbrahimOsama Ibrahim

              786




              786

























                  0














                  First you load the model in your controller:



                  $this->load->model('your_model_name_m');


                  Then you can use the model in your controller:



                  $logged_in = $this->your_model_name_m->login_check('me@us.com', 'password!#$');


                  If you frequently use this model, you can also autoload it via the config file in the model section:



                  $autoload['model'] = array( "your_model_name" );





                  share|improve this answer




























                    0














                    First you load the model in your controller:



                    $this->load->model('your_model_name_m');


                    Then you can use the model in your controller:



                    $logged_in = $this->your_model_name_m->login_check('me@us.com', 'password!#$');


                    If you frequently use this model, you can also autoload it via the config file in the model section:



                    $autoload['model'] = array( "your_model_name" );





                    share|improve this answer


























                      0












                      0








                      0







                      First you load the model in your controller:



                      $this->load->model('your_model_name_m');


                      Then you can use the model in your controller:



                      $logged_in = $this->your_model_name_m->login_check('me@us.com', 'password!#$');


                      If you frequently use this model, you can also autoload it via the config file in the model section:



                      $autoload['model'] = array( "your_model_name" );





                      share|improve this answer













                      First you load the model in your controller:



                      $this->load->model('your_model_name_m');


                      Then you can use the model in your controller:



                      $logged_in = $this->your_model_name_m->login_check('me@us.com', 'password!#$');


                      If you frequently use this model, you can also autoload it via the config file in the model section:



                      $autoload['model'] = array( "your_model_name" );






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 13 '18 at 10:52









                      JosFabreJosFabre

                      5921611




                      5921611























                          0














                          Your Model



                          Use brackets with your database condition



                          public function login_check($email, $password){
                          $this->db->select('registrasi.user_id,
                          registrasi.username_user,
                          registrasi.email_user,
                          registrasi.password_user')
                          ->from('registrasi')
                          ->where("(registrasi.email_user = '$email' OR registrasi.username_user = '$email' )");

                          $query = $this->db->get();
                          if($query->num_rows() == 1){
                          return $query->row();
                          } else {
                          return false;
                          }
                          }


                          Your Controller



                          if(isset($myquery) && $myquery != ''){
                          //foreach loop
                          }else{
                          //No record found
                          }


                          You can also use where() and or_where() for your condition



                          Read More






                          share|improve this answer




























                            0














                            Your Model



                            Use brackets with your database condition



                            public function login_check($email, $password){
                            $this->db->select('registrasi.user_id,
                            registrasi.username_user,
                            registrasi.email_user,
                            registrasi.password_user')
                            ->from('registrasi')
                            ->where("(registrasi.email_user = '$email' OR registrasi.username_user = '$email' )");

                            $query = $this->db->get();
                            if($query->num_rows() == 1){
                            return $query->row();
                            } else {
                            return false;
                            }
                            }


                            Your Controller



                            if(isset($myquery) && $myquery != ''){
                            //foreach loop
                            }else{
                            //No record found
                            }


                            You can also use where() and or_where() for your condition



                            Read More






                            share|improve this answer


























                              0












                              0








                              0







                              Your Model



                              Use brackets with your database condition



                              public function login_check($email, $password){
                              $this->db->select('registrasi.user_id,
                              registrasi.username_user,
                              registrasi.email_user,
                              registrasi.password_user')
                              ->from('registrasi')
                              ->where("(registrasi.email_user = '$email' OR registrasi.username_user = '$email' )");

                              $query = $this->db->get();
                              if($query->num_rows() == 1){
                              return $query->row();
                              } else {
                              return false;
                              }
                              }


                              Your Controller



                              if(isset($myquery) && $myquery != ''){
                              //foreach loop
                              }else{
                              //No record found
                              }


                              You can also use where() and or_where() for your condition



                              Read More






                              share|improve this answer













                              Your Model



                              Use brackets with your database condition



                              public function login_check($email, $password){
                              $this->db->select('registrasi.user_id,
                              registrasi.username_user,
                              registrasi.email_user,
                              registrasi.password_user')
                              ->from('registrasi')
                              ->where("(registrasi.email_user = '$email' OR registrasi.username_user = '$email' )");

                              $query = $this->db->get();
                              if($query->num_rows() == 1){
                              return $query->row();
                              } else {
                              return false;
                              }
                              }


                              Your Controller



                              if(isset($myquery) && $myquery != ''){
                              //foreach loop
                              }else{
                              //No record found
                              }


                              You can also use where() and or_where() for your condition



                              Read More







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 13 '18 at 12:02









                              Danish AliDanish Ali

                              1,70131021




                              1,70131021























                                  0














                                  Try by replacing



                                  if($myquery==TRUE){ 
                                  // your code
                                  }


                                  with



                                  if($myquery){ 
                                  // your code
                                  }





                                  share|improve this answer






























                                    0














                                    Try by replacing



                                    if($myquery==TRUE){ 
                                    // your code
                                    }


                                    with



                                    if($myquery){ 
                                    // your code
                                    }





                                    share|improve this answer




























                                      0












                                      0








                                      0







                                      Try by replacing



                                      if($myquery==TRUE){ 
                                      // your code
                                      }


                                      with



                                      if($myquery){ 
                                      // your code
                                      }





                                      share|improve this answer















                                      Try by replacing



                                      if($myquery==TRUE){ 
                                      // your code
                                      }


                                      with



                                      if($myquery){ 
                                      // your code
                                      }






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Nov 16 '18 at 4:37

























                                      answered Nov 13 '18 at 11:17









                                      TwinkleTwinkle

                                      173211




                                      173211






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53279053%2fhow-to-set-userdata-login-codeigniter%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          List item for chat from Array inside array React Native

                                          Thiostrepton

                                          Caerphilly