Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:14:54+00:00 2026-05-25T18:14:54+00:00

I want insert in the row from database, array of values as that each

  • 0

I want insert in the row from database, array of values as that each of they put in new row from database.

I not want insert all values in a row from database with use of serialize(json_encode or etc).

For example:(in this example, i want three times insert data(value), because i have 3 value different)
Update 4:

this my value:

<input name="name[0][]" value="11">
<input name="passport_number[0][]" value="11">


<input name="name[1][]" value="22">
<input name="passport_number[1][]" value="22">

i do it, but it not worked:

$name_input = $this->input->post('name');
$passport_number_input        = $this->input->post('passport_number');
//$term_passport_input = $this->input->post('term_passport');
//$date_of_birth_input       = $this->input->post('date_of_birth');
//$age_input        = $this->input->post('age');
//$national_number_input = $this->input->post('national_number');
//$mobile_input       = $this->input->post('mobile');
//$address_input        = $this->input->post('address');

$data = array();
foreach ($name_input as $idx => $name) {
    $data[] = array(
        'name' => $name_input[0]
        'passport_number' => $passport_number_input[0],
        //'term_passport' => $term_passport_input[$idx],
        //'date_of_birth' => $date_of_birth_input[$idx],
        //'age' => $age_input[$idx],
        //'national_number' => $national_number_input[$idx],
        //'mobile' => $mobile_input[$idx],
        //'address' => $address_input[$idx],
    );
};
var_dump($name_input);
$this->db->insert_batch('customer_info', $data);

This is output ‘$name_input’ with var_dump:

array(2) {
    [0] = > array(1) {
        [0] = > string(2)"11"
    }[1] = > array(1) {
        [0] = > string(2)"22"
    }
}

I get this error:

A PHP Error was encountered
Severity: Warning
Message: Cannot
modify header information – headers already sent by (output started at
D:\xampp\htdocs\application\controllers\admin\tour_foreign.php:405)
Filename: core/Common.php
Line Number: 413

A Database
Error Occurred
Error Number: 1054
Unknown column ‘0’ in ‘field
list’
INSERT INTO customer_info (0) VALUES (’22’)
Filename: D:\xampp\htdocs\system\database\DB_driver.php
Line
Number: 330

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:14:55+00:00Added an answer on May 25, 2026 at 6:14 pm

    Update 3: Per updated question (update 4)
    Looking at the var_dump of $name_input following code should work:

    $name_input = $this->input->post('name');
    $passport_number_input = $this->input->post('passport_number');
    
    $data = array();
    foreach ($name_input as $idx => $name) {
        $data[] = array(
            'name' => $name_input[$idx][0],
            'passport_number' => $passport_number_input[$idx][0]
        );
    };
    $this->db->insert_batch('customer_info', $data);
    

    It is further needed to access the [0] element as the POST input is passes as an array of arrays

    Update 2:
    Seeing the problem is because the POST returns the data as a further array following code MIGHT work. I would need var_dump of POST inputs ($hi_input..) to give the exact code.

    $hi_input    = $this->input->post('hi');
    $hello_input = $this->input->post('hello');
    $how_input   = $this->input->post('how');
    
    $data = array();
    foreach ($hi_input as $idx => $name) {
        $data[] = array(
            'hi' => $hi_input[$idx][0],
            'hello' => $hello_input[$idx][0],
            'how' => $how_input[$idx][0]
        );
    };
    $this->db->insert_batch('table', $data);
    

    The following code should work as I have tested it (I do not have CodeIgniter Installed). It does not use CodeIgniter to get post data.

    $hi_input    = $_POST['hi'];
    $hello_input = $_POST['hello'];
    $how_input   = $_POST['how'];
    
    $data = array();
    foreach ($hi_input as $idx => $name) {
        $data[] = array(
            'hi' => $hi_input[$idx][0],
            'hello' => $hello_input[$idx][0],
            'how' => $how_input[$idx][0]
        );
    }; 
    $this->db->insert_batch('table', $data);
    

    Update :
    You can also do this using $this->db->insert_batch();, like this :

    $hi_input    = $this->input->post('hi');
    $hello_input = $this->input->post('hello');
    $how_input   = $this->input->post('how');
    
    $data = array();
    foreach ($hi_input as $idx => $name) {
        $data[] = array(
            'hi' => $hi_input[$idx],
            'hello' => $hello_input[$idx],
            'how' => $how_input[$idx]
        );
    };
    $this->db->insert_batch('table', $data);
    

    Old answer
    The CodeIgniter documentation on insert – http://codeigniter.com/user_guide/database/active_record.html#insert
    states that the $data parameter is an associative array with column names as keys and data to insert as values.

    So you need to call it once for each row. Thus
    Try this:

    $hi_input    = $this->input->post('hi');
    $hello_input = $this->input->post('hello');
    $how_input   = $this->input->post('how');
    
    foreach ($hi_input as $idx => $name) {
        $data = array(
            'hi' => $hi_input[$idx],
            'hello' => $hello_input[$idx],
            'how' => $how_input[$idx]
        );
        $this->db->insert('table', $data);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert a new row into an Access database. I'm looking at
so the problem is, that i want to insert a new row after another
I insert several( array ) value with json_encode in one row from database table,
I want insert following checkbox in a row from database table, but have error,
I want to insert a row into the Database using SqlDataAdapter. I've 2 tables
I want to insert a value from the database into my dropdown menu in
I want to prevent the database from storing any values bigger than 20 into
I am new to iphone development.I want to insert multiple values into my sqlite3
I want to use a database table as a queue. I want to insert
I inserted on a row of database table values, now I want echo them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.