Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

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
          $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);

Open in new window


Model code
   function form_insert($data){
            $this->db->insert('tb_orgao', $data);
    }
    

Open in new window


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;

Open in new window


Thanks in advance.
SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eduardo Fuerte

ASKER

Hi Everybody

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_insert($data);

I installed and I'm going to use FirePHP

Thank you for the assistance.
Glad you've got it sorted!