I have 2 tables:
table: tbl_project
---------------------------------------
| PID | ProjectName | StartDate |
---------------------------------------
table: tbl_chart
-------------------------------------------------------------------------
| PID | P_ProjectPreparation | P_ConceptualDesign | P_Realization |
-------------------------------------------------------------------------
PID in table tbl_project
is the Primary Key. And the ProjectID in tbl_chart
references PID in tbl_project
.
I want if I click save for the data to insert into tbl_project
also in tbl_chart
insert the new PID automatically, and the value at column P_ProjectPreparation
etc is 0.
I've tried query at the Model like this :
<?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->db->query($sql);
}
}
Here is my controller :
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class admin_c extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
$this->load->model('admin_m');
}
public function index()
{
$this->load->view('admin_v');
}
public function save()
{
$data['PID'] = $this->input->post('PID');
$data['ProjectName'] = $this->input->post('ProjectName');
$data['StartDate'] = $this->input->post('StartDate');
$this->admin_m->save($data);
$this->load->view('admin_v');
}
}
Here is my view code for the save button :
<form action="<?PHP echo site_url(); ?>/admin_c/save" method="post">
I get an error from the model. Any ideas what could be wrong with the query?