im trying to write a code where a form will store all of its values inside session variables when the submit button is pressed and go to the next page where there is another form waiting to be filled up. when the submit button for the form in page 2 is pressed the variables will be stored in a session then the contents of the session variables/array will be inserted in the database. and i seem to be having problems
Summary:
-
Page 1 – User fills up form and the variables will be stored in a session array upon submit
-
Page 2 – user fills up another form and the variables will be stored in a session array upon submit
-
the session variables in page 1 and 2 will be inserted in the database
here is my code:
controller(site.php)
public function m1()
{
if(isset($_POST['m1']))
{
$suffix = $this->input->post("suffix");
$fn = $this->input->post("fn");
$mn = $this->input->post("mn");
$ln = $this->input->post("ln");
$nickname = $this->input->post("nickname");
$sex = $this->input->post("sex");
$bday = $this->input->post("bday");
$street = $this->input->post("street");
$city = $this->input->post("city");
$province = $this->input->post("province");
$region = $this->input->post("region");
$landline = $this->input->post("landline");
$cellphone = $this->input->post("cellphone");
$email = $this->input->post("email");
$edu_level = $this->input->post("edu_level");
$course = $this->input->post("course");
$school_name = $this->input->post("school_name");
$school_address = $this->input->post("school_address");
$school_province = $this->input->post("school_province");
$school_city = $this->input->post("school_city");
$school_region = $this->input->post("school_region");
$newdata = array('suffix'=>$suffix,
'fn'=>$fn,
'mn'=>$mn,
'ln'=>$ln,
'nickname'=>$nickname,
'sex'=>$sex,
'bday'=>$bday,
'street'=>$street,
'city'=>$city,
'province'=>$province,
'region'=>$region,
'landline'=>$landline,
'cellphone'=>$cellphone,
'email'=>$email,
'edu_level'=>$edu_level,
'course'=>$course,
'school_name'=>$school_name,
'school_address'=>$school_address,
'school_province'=>$school_province,
'school_city'=>$school_city,
'school_region'=>$school_region,
);
$this->session->set_userdata($newdata);
redirect(base_url() . "site/cmain/m/2");
}
}
public function m2()
{
if(isset($_POST['m2']))
{
$nature_complaint = $this->input->post("nature_complaint");
$newdata = array('nature_complaint'=>$nature_complaint);
$this->session->set_userdata($newdata);
$this->db->insert('myself', $newdata);
redirect(base_url() . "site/cmain/m/3");
}
}
the problem with my code is that the session variables for page 2(public function m2()) is the only one that gets inserted in the database.
is there a way to fix this?
thanks
In the first function (M1)
set your newdata in this way
In second function (M2)