Welcome Guest, Not a member yet? Register   Sign In
Losing $_SESSION and $_POST variables
#1

This isn’t making any sense to me ? I have session_start(); in index.php at C:\xampp\htdocs and I know it’s being called every time a new php file is called as there’s always an error of
Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\index.php on line 2
When I set ‘session.auto_start = 1’ in php.ini
So I have it set to session.auto_start = 0

So, why when I move from the controller to the model and then back to the controller are some $_POST &/or $_SESSION variables being lost??
When I first go into the page I am interested in and I have an echo or print_r on the $_SESSION or $_POST they’re set, but when it goes to a call to the model to save data to database and returns to the controller some (not all) have been lost.

If I have    public function add_extra_items ($list_name, $start, $end){

} in the controller, when it comes back from the model I get errors of
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Diet_plan::add_extra_items()
Filename: controllers/diet_plan.php
Line Number: 634
And  I cannot access the list_name, start and end

If I have    public function add_extra_items ($list_name=NULL, $start= NULL, $end = NULL){

} in the controller I don’t get the errors, but the list_name, start and end are no longer available either
i put in
Code:
                               $_SESSION['start'] = $start;
                               $_POST['start'] = $start;
                               echo "session start = ". $_SESSION['start']; //retrieve session start data
                               echo "post start = ". $_POST['start']; //retrieve post start data

                                $_SESSION['end'] = $end;
                                $_POST['end'] = $end;
                                echo "session end = ". $_SESSION['end']; //retrieve session end data
                                echo "post end = ". $_POST['end']; //retrieve post end data

                               print_r($_SESSION);
                               print_r($_POST);
and i get
session start = 2015-06-06post start = 2015-06-06session end = 2015-06-07post end = 2015-06-07Array ( [uid] => 2 [startdate] => [enddate] => [desc] => 1,2,3,4,5,6,7
  • => richmond [id] => 15 [remove] => [start] => 2015-06-06 [end] => 2015-06-07 ) Array ( [extra_item_id] => Array ( [0] => invalid ) [extra_items] => 1 [btnSubmit_x] => 56 [btnSubmit_y] => 52 [start] => 2015-06-06 [end] => 2015-06-07 )

    All good up to here

    After I post some info in the form and press submit, to go to the database it runs this code
    Code:
    $extra_items = new Extra_item();
    $extra_items->order_by('description', 'asc')->get_iterated();

    if($extra_items->exists()){
       $data['extra_items'] = $extra_items; // Populate extra_item dropdown Data  
        $this->form_validation->set_rules($config);
        $this->form_validation->set_error_delimiters('<div class="error">', '</div>');
               if ($this->form_validation->run() == FALSE) {
                   // Extra Item Not Created
                }else {
                       $date = new Extra_item_date();
                       $item_rows = array();
                       $post_dates = $this->input->post('extra_item_date');                                  
                       $post_amounts = $this->input->post('extra_item_amount');  
                        $post_hours = $this->input->post('extra_item_hours');  
                         $post_items = $this->input->post('extra_item_id');
                          foreach($post_amounts AS $index => $item) {                           if(!empty($post_hours[$index])&&(!empty($post_items[$index]))&&(!empty($post_dates[$index]))) {
                                       echo "definately here  ";  
                                       $item_rows[] = array('amount' => $item, 'hours' => $post_hours[$index], 'extra_item' => $post_items[$index],'extra_date' => $post_dates[$index]);
                      }
          }
                $date->item_rows = $item_rows;  
                       if($date->create() === TRUE) { // Attempt to create the extra_item_date data
                              // Success
                              $data['success'] = 'The extra item data has been entered into the database.';
                                   echo $id;
                                   echo "here is id";
                           }else {
                               // Failure
                                $data['error'] = $date->error->create;
                            }
                     }
    }else {
          $data['error'] = 'No extra items for your login.';
    }
    Then what comes out is the following

    session start = post start = session end = post end = Array ( [uid] => 2 [startdate] => [enddate] => [desc] => 1,2,3,4,5,6,7
    • => richmond [id] => 15 [remove] => [start] => [end] => ) Array ( [extra_item_date] => Array ( [0] => 09 June 2015 ) [extra_item_amount] => Array ( [0] => 9 ) [extra_item_hours] => Array ( [0] => 9 ) [extra_item_id] => Array ( [0] => 7 ) [submit] => Add the extra item/s [start] => [end] => ) definately here Array ( [0] => Array ( [amount] => 9 [hours] => 9 [extra_item] => 7 [extra_date] => 09 June 2015 ) ) Array ( [extra_item_date] => Array ( [0] => 09 June 2015 ) [extra_item_amount] => Array ( [0] => 9 ) [extra_item_hours] => Array ( [0] => 9 ) [extra_item_id] => Array ( [0] => 7 ) [submit] => Add the extra item/s [start] => [end] => ) Array ( [uid] => 2 [startdate] => [enddate] => [desc] => 1,2,3,4,5,6,7
      • => richmond [id] => 15 [remove] => [start] => [end] => ) 09 June 2015997new entry15here is id
        session start = post start = session end = post end =
        are empty and yet id, list and desc are not !
        I need the start and end dates for further processing but they are no longer available and I am wondering why and how can I change code so they are ?

        Thanks to all for help
Reply
#2

Did you try codeigniter's session library? See documentation http://www.codeigniter.com/userguide3/li...sions.html. You are not supposed to use session_start manually.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB