Welcome Guest, Not a member yet? Register   Sign In
[Solved] Post data NULL - Have no idea why
#1

(This post was last modified: 06-25-2020, 10:55 AM by jreklund.)

Hi, I am working on an application for Social Workers in a Non-Profit. I am fairly new to Codeigniter, but have written apps previously.

I am starting to think that I have an install problem with this app and would like your help.

My View
PHP Code:
<div class="row">
  <div class="col-md-12">
    <p>Below is a list of Clients belonging to Funda NenjaTheir details are in summaryYou can get more details by clicking the more button, or you can edit the client by clicking edit </p>
    <class="btn btn-primary btn" href="<?php echo base_url('database/human'); ?>" role="button">
      << Back</a> <br /><br /><br />
      <form method="post" action="<?php echo base_url('database/human_form_add_val'); ?>" >
      <?php  
      
if($this->uri->segment(2) == "inserted"
      {
        echo "<p class='text-success'>Data Inserted</p>";
      }
      ?>
        <div class="row">
          <div id='form-group' class='col'>
            <input type="text" class="form-control" id="fname" placeholder="Enter First Name"><br />
            <span class="text-danger"><?php echo form_error("fname"); ?></span>
            <input type="text" class="form-control" id="mnames" placeholder="Enter Middel Names"><br />
            <span class="text-danger"><?php echo form_error("mnames"); ?></span>
            <input type="text" class="form-control" id="lname" placeholder="Enter Surname"><br />
            <span class="text-danger"><?php echo form_error("lname"); ?></span>
            <input type="text" class="form-control" id="id_num" placeholder="Enter ID Number"><br />
            <span class="text-danger"><?php echo form_error("id_num"); ?></span>
          </div>
          <div id='form-group' class='col'>
            <input type="text" class="form-control" id="address" placeholder="Enter address in one line"><br />
            <span class="text-danger"><?php echo form_error("address"); ?></span>
            <input type="text" class="form-control" id="gps_loc" placeholder="Enter GPS coordinates"><br />
            <span class="text-danger"><?php echo form_error("gps_loc"); ?></span>
            <input type="text" class="form-control" id="t_num" placeholder="Enter Telephone Number"><br />
            <span class="text-danger"><?php echo form_error("t_num"); ?></span>
            <input type="text" class="form-control" id="contact_name" placeholder="Enter Telephone Contact Name"><br />
            <span class="text-danger"><?php echo form_error("contact_name"); ?></span>
          </div>
        </div>
        <input class="btn btn-primary btn-lg btn-block" name="insert" type="submit" value="Submit">
      </form>
  </div>
</div>

<hr>

</div>
</main> 

My Model
PHP Code:
<?php
defined
('BASEPATH') or exit('No direct script access allowed');

class 
Client_list extends CI_Model
{

        public function __construct()
        {
        }
        
        
        
function get_doc()
        {
                $this->db->select('*');
                $this->db->from('client');
                $query $this->db->get();
                return $query;
        }

        function insert_client($data)
        {
                $this->db->insert("client"$data);
        }

        


My Controller
PHP Code:
    public function human_form_add_val()
    {


        
/* ============================================================= */
        /* VALIDATE AND SAVE THE DATA FROM THE FORM */
        /* ============================================================= */

        /* Set the page title here */
        
$data['page_name'] = 'Something went Wrong';

        
/* Get the Header Elements */
        
$this->load->view('template/001_head');

        
/* Get the Header Elements */
        
$this->load->view('template/001_head');

        
/* Get the Navigation */
        
$this->load->view('template/002_nav');

        
/* Open the body section */
        
$this->load->view('template/003_body_open');

        
/* Display the title of the page as a headline */
        
$this->load->view('includes/head'$data);


        
$this->form_validation->set_rules("fname"'First Name''alpha');
        
$this->form_validation->set_rules("mnames"'Middle Names''alpha');
        
$this->form_validation->set_rules("lname"'Last Name''alpha');
        
$this->form_validation->set_rules("id_num"'ID Number''numeric');
        
$this->form_validation->set_rules("address"'Address''alpha_numeric');
        
$this->form_validation->set_rules("gps_loc"'GPS Location''alpha_numeric');
        
$this->form_validation->set_rules("t_num"'Telephone Number''numeric');
        
$this->form_validation->set_rules("contact_name"'Phone Contact Name''alpha');
        
        if(
$this->form_validation->run())
        {
            
//True
            
$this->load->model("client_list");
            
$data = array(
                
"fname"            => $this->input->post("fname"),
                
"mnames"        => $this->input->post("mnames"),
                
"lname"            => $this->input->post("lname"),
                
"id_num"        => $this->input->post("id_num"),
                
"address"        => $this->input->post("address"),
                
"gps_loc"        => $this->input->post("gps_loc"),
                
"t_num"            => $this->input->post("t_num"),
                
"contact_name"    => $this->input->post("contact_name")
            );
            
$this->client_list->insert_client($data);
            
redirect(base_url("database/human_form_add"));
            }
                else
        {
            
//false
            
$this->load->view('forms/hum_add');
        }

        
/* Finish the page with the footer */
        
$this->load->view('template/004_footer');
    }



When I submit the form, all post data is NULL as detailed below:
INSERT INTO `client` (`fname`, `mnames`, `lname`, `id_num`, `address`, `gps_loc`, `t_num`, `contact_name`) VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

What am I doing wrong?
Reply
#2

This have been solved in CodeIgniter Slack channel. Missing name="" fields on all input fields.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB