0

First sorry for my English.

I have a weird problem using the php $_SESSION Object. I spent 2 days without find the solution. I am triying to save a multidimensional array that stores some post values. I create an array with this values and then i create a multidimensional array containing this arrays.

Page 1 (setvalues in multi array ans save in session)-> GET -> Page 2 read the session.

My code Page 1:

First, save the post values into a object property and validate them.

public function validateData(){

        $this->nombres=$_POST["nombre"];
        $this->imp_nombres=$_POST["imp_nombre"];
        $this->numeros=$_POST["numero"];
        $this->imp_numeros=$_POST["imp_numero"];
        $this->tallas=$_POST["talla"];
        $this->cantidades=$_POST["cantidad"];
        $this->productos=$_POST["products"];
        $this->equipos=$_POST["equipo"];


        if(WSI_Funtions::compareSizes($this->nombres,$this->imp_nombres,$this->numeros,$this->imp_numeros,$this->tallas,$this->cantidades,$this->productos,$this->equipos))
        {
            $this->isValidModel=true;
            $this->saveProductsValues();

        }
        else{
          $this->isValidModel=false;
          $this->errorMessage="Los datos no son correctos. Los parametros no coinciden";
        }

}

If data is ok, I save those values:

public function saveProductsValues()
{


    $this->productsValues=array();
    $this->productsValues["names"]=$this->nombres;
    $this->productsValues["imp_nombres"]=$this->imp_nombres;
    $this->productsValues["numeros"]=$this->numeros;
    $this->productsValues["imp_numeros"]=$this->imp_numeros;
    $this->productsValues["tallas"]=$this->tallas;
    $this->productsValues["cantidades"]=$this->cantidades;
    $this->productsValues["productos"]=$this->productos;
    $this->productsValues["equipos"]=$this->equipos;


}

Then I save it in a session :

public function saveSessionValues()
{
    $_SESSION['customer'] = $this->customerObject;
    $_SESSION['productsValues'] =$this->productsValues;
    echo var_dump($_SESSION['productsValues']); 
}

The saveSessionValues echo print this:

array(8) { ["names"]=> array(12) { [0]=> string(0) "" [1]=> string(12) "ÁNGEL HDEZ." [2]=> string(11) "VUJASINOVIC" [3]=> string(4) "ABIA" [4]=> string(10) "MUTAKABBIR" [5]=> string(8) "PETROVIC" [6]=> string(5) "DOBOS" [7]=> string(4) "HOMS" [8]=> string(6) "CASTRO" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["imp_nombres"]=> array(12) { [0]=> string(0) "" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["numeros"]=> array(12) { [0]=> string(1) "7" [1]=> string(1) "8" [2]=> string(1) "9" [3]=> string(0) "" [4]=> string(2) "11" [5]=> string(2) "12" [6]=> string(2) "18" [7]=> string(2) "19" [8]=> string(2) "22" [9]=> string(1) "5" [10]=> string(2) "33" [11]=> string(0) "" } ["imp_numeros"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(0) "" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(0) "" } ["tallas"]=> array(12) { [0]=> string(4) "XXXL" [1]=> string(3) "XXL" [2]=> string(2) "XL" [3]=> string(3) "XXL" [4]=> string(3) "XXL" [5]=> string(3) "XXL" [6]=> string(4) "XXXL" [7]=> string(3) "XXL" [8]=> string(2) "XL" [9]=> string(4) "XXXL" [10]=> string(2) "XL" [11]=> string(3) "XXL" } ["cantidades"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(3) "145" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(1) "1" } ["productos"]=> array(12) { [0]=> string(3) "109" [1]=> string(3) "109" [2]=> string(3) "109" [3]=> string(3) "109" [4]=> string(3) "109" [5]=> string(3) "109" [6]=> string(3) "109" [7]=> string(3) "109" [8]=> string(3) "109" [9]=> string(3) "109" [10]=> string(3) "109" [11]=> string(3) "109" } ["equipos"]=> array(12) { [0]=> string(7) "LEB ORO" [1]=> string(7) "LEB ORO" [2]=> string(7) "LEB ORO" [3]=> string(7) "LEB ORO" [4]=> string(7) "LEB ORO" [5]=> string(7) "LEB ORO" [6]=> string(12) "ES TALLA 4XL" [7]=> string(7) "LEB ORO" [8]=> string(7) "LEB ORO" [9]=> string(12) "ES TALLA 4XL" [10]=> string(7) "LEB ORO" [11]=> string(7) "LEB ORO" } }

My code Page 2 (php tags ommitted):

if (!isset($_SESSION)) { session_start(); }
echo var_dump($_SESSION['productsValues']);

This echo print the next value:

array(8) { ["names"]=> NULL ["imp_nombres"]=> NULL ["numeros"]=> NULL ["imp_numeros"]=> NULL ["tallas"]=> NULL ["cantidades"]=> NULL ["productos"]=> NULL ["equipos"]=> NULL }

The first level array exists, because the subarrays keys are printed, but all the second level arrays are NULL..

Maybe is for use the $_POST value?? I had try to encode the values of the $_POST object, saving only a json string instead of saving a object with the same result, the first nodes in the JSON are the keys of the arrays but the values are "NULL"

Any help please?? Thanks!!

1
  • maybe you need to return an array from saveProductsValues() Commented Jun 15, 2015 at 8:40

1 Answer 1

2

You are over writing the values. Try with -

$_SESSION['productsValues'][] = $this->productsValues;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.