Welcome Guest, Not a member yet? Register   Sign In
Database is getting populated only once...............pls help
#1

[eluser]noname525[/eluser]
vv
#2

[eluser]InsiteFX[/eluser]
Show your SQL table!
#3

[eluser]noname525[/eluser]
vv
#4

[eluser]meigwilym[/eluser]
You're only using one insert statement:

Code:
public function reportadder()
{
  $insert_data = array( ‘rid’ => ‘NULL’,
‘labno’ => $this->input->post(‘labno’),
      ‘location’ => $this->input->post(‘loca’),
      ‘date’ => $this->input->post(‘tdate’),
      ‘name’ => $this->input->post(‘pname’),
      ‘age’ => $this->input->post(‘ages’),
      ‘sex’ => $this->input->post(‘sex’),
      ‘refdoc’ => $this->input->post(‘dselect1’),        
      ‘test’ => $this->input->post(‘tessel’));

// this is the only insert you're doing:
    $insert1=$this->db->insert(‘report’, $insert_data);
                            }

You could improve your code by naming the model 'report' instead of 'database'.

It's usual to have a number of models, each for one table in the database.

In this case I'd suggest something like

Code:
// application/models/report.php

public function add()
{
  $insert_data = array( ‘rid’ => ‘NULL’,
      ‘labno’ => $this->input->post(‘labno’),
      ‘location’ => $this->input->post(‘loca’),
      ‘date’ => $this->input->post(‘tdate’),
      ‘name’ => $this->input->post(‘pname’),
      ‘age’ => $this->input->post(‘ages’),
      ‘sex’ => $this->input->post(‘sex’),
      ‘refdoc’ => $this->input->post(‘dselect1’),        
      ‘test’ => $this->input->post(‘tessel’));

    return $this->db->insert(‘report’, $insert_data);
}

Then using it like this:
Code:
public function insertrec()
      {
            $this->load->model(‘report’);
            $this->report->add();
            $this->tmain();
          
      }

I'm afraid I don't have the time to explain why you should be passing the data to the model <b>after</b> validation, but please look at the <a href="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html">Form Validation</a> class.
#5

[eluser]InsiteFX[/eluser]
Code:
public function reportadder()
{
    $insert_data = array();    // clears out the array.

    $insert_data = array(
        'rid'      => NULL,
        'labno'    => $this->input->post('labno'),
        'location' => $this->input->post('loca'),
        'date'     => $this->input->post('tdate'),
        'name'     => $this->input->post('pname'),
        'age'      => $this->input->post('ages'),
        'sex'      => $this->input->post('sex'),
        'refdoc'   => $this->input->post('dselect1'),        
        'test'     => $this->input->post('tessel')
    );

    // this is the only insert you're doing:
    $insert1 = $this->db->insert('report', $insert_data);
}

// Please use code tags for your code!
// [code]
// your code here!
// [/code ]  Remove the space after code

It should add a new entry every time you call it. If you only call it
once then it will only insert one database record.
#6

[eluser]noname525[/eluser]
vv




Theme © iAndrew 2016 - Forum software by © MyBB