title: Insert data into two tables using php and codeigniter
body: <p>I have 2 tables:</p>
  
  <pre><code>table: tbl_project
  ---------------------------------------
  | PID | ProjectName | StartDate |
  ---------------------------------------
  
  table: tbl_chart
  -------------------------------------------------------------------------
  | PID | P_ProjectPreparation | P_ConceptualDesign | P_Realization |
  -------------------------------------------------------------------------
  </code></pre>
  
  <p>PID in table <code>tbl_project</code> is the Primary Key. And the ProjectID in <code>tbl_chart</code> references PID in <code>tbl_project</code>.</p>
  
  <p><img src="https://i.stack.imgur.com/sscDY.jpg" alt="here is my add project form"></p>
  
  <p>I want if I click save for the data to insert into <code>tbl_project</code> also in <code>tbl_chart</code> insert the new PID automatically, and the value at column <code>P_ProjectPreparation</code> etc is 0.</p>
  
  <p>I've tried query at the Model like this :</p>
  
  <pre><code>&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');
  
  class admin_m extends CI_Model {
      function __construct()
      {
          // Call the Model constructor
          parent::__construct();
      }
  
      public function save($data)
      {
          $sql = "insert into tbl_project values('".$data['PID']."','".$data['ProjectName']."', '".$data['StartDate']."') ; insert into tbl_chart (PID) values ('".$data['PID']."')";
          $this-&gt;db-&gt;query($sql);
       } 
  }
  </code></pre>
  
  <p>Here is my controller :</p>
  
  <pre><code>&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');
  
  class admin_c extends CI_Controller {
  
      public function __construct()
      {
          parent::__construct();
  
          $this-&gt;load-&gt;database();
          $this-&gt;load-&gt;helper('url');
          $this-&gt;load-&gt;model('admin_m');
      }
  
      public function index()
      {
          $this-&gt;load-&gt;view('admin_v');
      }
  
      public function save()
      {
          $data['PID'] = $this-&gt;input-&gt;post('PID');
          $data['ProjectName'] = $this-&gt;input-&gt;post('ProjectName');
          $data['StartDate'] = $this-&gt;input-&gt;post('StartDate');
  
          $this-&gt;admin_m-&gt;save($data);
          $this-&gt;load-&gt;view('admin_v');
       } 
  }
  </code></pre>
  
  <p>Here is my view code for the save button :</p>
  
  <pre><code>&lt;form action="&lt;?PHP echo site_url(); ?&gt;/admin_c/save" method="post"&gt;
  </code></pre>
  
  <p>I get an error from the model. Any ideas what could be wrong with the query?</p>