php - insert data in corresponding tables from multistep form -


i have multistep form called "card"

this form must contain sevral information of person, person has done, job of person, tools person used etc.

to solve , make more cool made multiform step form, when user finishes filling data first table (for instace information of tools used) user clicks on next step button , inputs other table showed (project person has worked)... keeps on going till user fills necessary data. save work using grocerycrud.

<form method="post" action="<?php echo base_url();?>controller/save" name="form"/>   <label>user name</label>   <input type="text" name="username">      <input type="submit" value="add"/>   <!--#######################        several more data store in distict tables    #######################    -->     </form>      in controller:    function save     {       $arrdata["username"] = $this->input->post("username");       $this->user_model->add($arrdata);      }    in user_model  function add($arrdata) {          if($this->db->insert(tablename, $arrdata))           return true;         else           return false;     }  

when redirecting controller work if fill 1 table.

the problem not know how store corresponding data other tables involved. if insert new registry in tablename new id assigned. liket use assigned id use other requiered field in other tables (the related tables have id foreign key)

how solve there like:

$last_id = $user->id; 

so keep inserting data other tables,

will useful use

$crud->set_relation('column','table','column'); 

maybe callbackor something, has have done inserting multiple related tables 1 form?

so if understanding correctly need hold userid insertion multiple tables after first insert right? that's easy enough, save id session (if person logged application should doing anyway @ login).

after initial insert runs can call this:

$this->session->set_userdata('userid',$this->db->insert_id()); 

then time need id pull session, example.

$array = (     'tool'=>'hammer',     'userid'=>$this->session->userdata('userid') ); $this->db->insert('tool_table',$array); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -