• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Form Post Not Working

#1
I've been stuck here for hours and I can not seem to find the source.

I have a simple login form.

Code:
<form method="post" class="m-t" role="form" action="<?php echo base_url();?>login/">
               <div class="form-group">
                   <input type="text" name="username" id="username" class="form-control" placeholder="Username" required="">
               </div>
               <div class="form-group">
                   <input type="password" name="password" id="password"  class="form-control" placeholder="Password" required="">
               </div>
               <button type="submit" class="btn btn-primary block full-width m-b">Login</button>

               <a href="#"><small>Forgot password?</small></a>
               <p class="text-muted text-center"><small>Do not have an account?</small></p>
               <!-- <a class="btn btn-sm btn-white btn-block" href="register.html">Create an account</a>  -->
           </form>

The Controller I am Posting to looks like this:
PHP Code:
class Login extends CI_Controller {

 
   public function _construct()
 
   {
 
       session_start();
 
       parent::__construct();
 
   }

    public function 
index()
    {
        
$check $this->session->userdata('logged_in');
        if(empty(
$check))
        {
         
  $this->load->view('templates/header.php');
     
      $this->load->view('pages/home');
     
      $this->load->view('templates/header.php');
        }
        else
        {
         
 $st $this->session->userdata('role');
         
 if($st=='worker')
         
 {
         
     header('location:'.base_url().'worker');    
          
}
         
 else if($st=='client')
         
 {
         
     header('location:'.base_url().'client');
         
 }
         
 else if($st=='sales')
         
 {
         
     header('location:'.base_url().'sales');
         
 }
         
 else if($st=='billing')
         
 {
         
     header('location:'.base_url().'billing');
         
 }
        }
    }


 
   public function login()
 
   {
 
      print_r($_POST);
 
      $u $this->input->post('username');
 
      $p $this->input->post('password');
 
      $this->web_app_model->getLoginData($u$p);
 
      
    
}



The POST DATA is in the array yet I get the following errors.
Quote:class Login extends CI_Controller {

    public function _construct()
    {
        session_start();
        parent::__construct();
    }

public function index()
{
$check = $this->session->userdata('logged_in');
if(empty($check))
{
   $this->load->view('templates/header.php');
       $this->load->view('pages/home');
       $this->load->view('templates/header.php');
}
else
{
  $st = $this->session->userdata('role');
  if($st=='worker')
  {
      header('location:'.base_url().'worker');    
  }
  else if($st=='client')
  {
      header('location:'.base_url().'client');
  }
  else if($st=='sales')
  {
      header('location:'.base_url().'sales');
  }
  else if($st=='billing')
  {
      header('location:'.base_url().'billing');
  }
}
}


    public function login()
    {
       print_r($_POST);
       $u = $this->input->post('username');
       $p = $this->input->post('password');
       $this->web_app_model->getLoginData($u, $p);
       
    }

}

Quote:A PHP Error was encountered
Severity: Error
Message: Call to a member function post() on null
Filename: controllers/Login.php
Line Number: 46
Backtrace:

I tried directly accessing the post data via $_POST as shown here:
PHP Code:
   public function login()
 
   {
 
      print_r($_POST);
 
      //$u = $this->input->post('username');
 
      //$p = $this->input->post('password');
 
      $u $_POST['username'];
 
      $p $_POST['password'];
 
      $this->web_app_model->getLoginData($u$p);
 
      
    


And then I get the following errors:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$web_app_model
Filename: controllers/Login.php
Line Number: 50
Backtrace:
File: C:\xampp\htdocs\mmmPortal\application\controllers\Login.php
Line: 50
Function: _error_handler

File: C:\xampp\htdocs\mmmPortal\index.php
Line: 315
Function: require_once

Quote:A PHP Error was encountered
Severity: Error
Message: Call to a member function getLoginData() on null
Filename: controllers/Login.php
Line Number: 50
Backtrace:

It seems anything that uses $this is not working yet it works in my other controllers and I've compared them over and over for basic structure errors.

Any help would be greatly appreciated!
Reply

#2
Isn't it "public function __construct()" (with two underscores)?

Also, why use "session_start()" (native php function), and then use "$this->session->userdata" (CodeIgniter specific method)? Why not load the session library and then remain using the library all the way around?

...Also, related to the "$this->web_app_model->getLoginData($u, $p);" error. Did you load the model before using it?
Reply

#3
(04-18-2018, 01:38 AM)Avenirer Wrote: Isn't it "public function __construct()" (with two underscores)?

Also, why use "session_start()" (native php function), and then use "$this->session->userdata" (CodeIgniter specific method)? Why not load the session library and then remain using the library all the way around?

...Also, related to the "$this->web_app_model->getLoginData($u, $p);" error. Did you load the model before using it?

I was following a tutorial from YouTube for getting mu authentication working. Both the single underscore and the session_start() method came from that tutorial and of course in the tutorial they do not encounter the issue I am having.

I am loading the web_app_model in in the config/autoload.php file.

Any similar occurrences of my issue I've found on google refer to issues with .htaccess and mod_rewrite but I have all of that setup and working as recommended. 

What seems interesting to me still is that post data is available via $_POST but not vie the Codeigniter method.

I am using the latest 3.1.8 build running on XAMPP 5.6.35

Is there some other Global step anyone can identify that could be causing this to fail?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.