Eduardo Fuerte
asked on
Could you point what is going wrong in this MySQL/ Codeigniter form data insertion ?
Hi Experts
Could you point what is going wrong in this MySQL/ Codeigniter form data insertion ?
Controller Code
Model code
MySQL table (auto increment)
Thanks in advance.
Could you point what is going wrong in this MySQL/ Codeigniter form data insertion ?
Controller Code
$dia = date('ymd');
$programa = $this->input->post('programa');
$orgao = $this->input->post('orgao');
// In ----PostgreSQL:---- This code runs fine
//$sql = "INSERT INTO tb_orgao(idorgao, idprograma, nome, data ) VALUES (nextval('id_seq_reg_orgao'::regclass),'%d', '%s', %s);";
//$comando = sprintf($sql, $orgao , $dia, $programa);
// $sql = pg_query($comando);
// Trying to insert directly into MySQL - no success
// $sql = "INSERT INTO tb_orgao(idprograma, nome, data) VALUES ('%s', '%s', %d);";
// $comando = sprintf($sql, $programa , $orgao, $dia );
// $sql = mysql_insert_id($comando);
// Or using model:
$sql = pg_query($comando);
$data = array(
'idprograma' => $programa,
'nome' => $orgao,
'data' => $dia
);
// Transfering data to Model
$this->orgao_model->form_insert($data);
Model code
function form_insert($data){
$this->db->insert('tb_orgao', $data);
}
MySQL table (auto increment)
CREATE TABLE tb_orgao
(
idorgao INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
idprograma INT(4) NOT NULL,
nome varchar(30) NOT NULL,
data date,
FOREIGN KEY (idprograma) REFERENCES tb_programa(idprograma)
)ENGINE = INNODB;
Thanks in advance.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad you've got it sorted!
ASKER
Sorry
What I did is to use the incorrect controller version ....
(this version really uses PstgreSQL)
Going to the "right" controller version, everything is ok.
mysql_query => runs ok but I used the default Codeigniter code for insertions
$this->orgao_model->form_i
I installed and I'm going to use FirePHP
Thank you for the assistance.