title: How to insert into multiple tables with CodeIgniter
body: <p>I have two tables that have (1:1) relationship between each others.</p>
  
  <pre><code>customers table:
   - customerID (PK)(AI)
   - customerName
   - phone
  
  addresses table:
   - customerID (PK&amp;FK)
   - address
   - city
   - zipcode
  </code></pre>
  
  <p>I tried to update them in the same CodeIgniter view form. </p>
  
  <p><strong>update_view.php</strong></p>
  
  <pre><code>&lt;th&gt;Customer Name:&lt;/th&gt;
  &lt;td&gt;&lt;input type="text" name="customerName"/&gt;&lt;/td&gt;
  &lt;tr&gt;
  &lt;th&gt;Customer Phone:&lt;/th&gt;
  &lt;td&gt;&lt;input type="text" name="phone"/&gt;&lt;/td&gt;
  &lt;tr&gt;
  &lt;th&gt;Address:&lt;/th&gt;
  &lt;td&gt;&lt;input type="text" name="address"/&gt;&lt;/td&gt;
  &lt;tr&gt;
  &lt;th&gt;City:&lt;/th&gt;
  &lt;td&gt;&lt;input type="text" name="city"/&gt;&lt;/td&gt;
  &lt;tr&gt;
  &lt;th&gt;Zip Code:&lt;/th&gt;
  &lt;td&gt;&lt;input type="text" name="zipcode"/&gt;&lt;/td&gt;
  </code></pre>
  
  <p>This is part of the my <strong>controller</strong> code:</p>
  
  <pre><code>    public function insert()
          {      
              $this-&gt;load-&gt;database();
              $this-&gt;load-&gt;model('my_model');
              $this-&gt;my_model-&gt;insert_entry();
  
              $custInsert=$this-&gt;my_model-&gt;get_all_customers();
              $this-&gt;load-&gt;view('main_view',array('customer'=&gt;$custInsert));
  ..
  }
  </code></pre>
  
  <p>Note: up to this point everything was working for process the one table (customers).</p>
  
  <p>This is the part of my <strong>model</strong> file:</p>
  
  <pre><code>function insert_entry()
      {
          $this-&gt;customerName   = $_POST['customerName']; 
          $this-&gt;phone = $_POST['phone'];
          $this-&gt;db-&gt;insert('customers', $this); // up to here it was working
  
          //$customerID=$db-&gt;insert_id;
          $customerID=$this-&gt;db-&gt;query("SELECT MAX(customerID) FROM `customers`");
          $this-&gt;customerID;
          $this-&gt;address = $_POST['address'];
          $this-&gt;city = $_POST['city'];
          $this-&gt;zipcode = $_POST['zipcode'];
          $this-&gt;db-&gt;insert('addresses', $this);
  }
  </code></pre>
  
  <p>As for me the problem is the 'addresses' table need to customerID, but I don't insert it handly (auto_increment). I tried to many way for get it after inserted to customers table but I cant do it. Is there anybody know different way or what should I do in that way?</p>