$ _Session variable does not write to the database

0

I'm using mysqli and I can not save information in the database.
I took the test with

echo var_dump($_SESSION); 
echo "<br />";
echo $_SESSION['login'];  


Return value was:
array (2) {["login"] = > string (6) "djalma" ["password"] = > string (3) "123"}

    <?php
    session_start();

        require '../php/funcao_mysql.php';

    $cod_os = $_POST['N_OS'];
    $cod_usuario = $_SESSION['login']; 

    $sql = $con->prepare("insert into ControleOS (cod_os, cod_usuario, cod_cliente, NomeCliente, DataOs, Hora, DescProbl, Tp_Instalacao, MuCaboCliente,  
            MuCaboBackBone, MuRJ45, MuEmendaBargoa, MuTomada, MuBenjamimAdaptador, MuEsticadorCaboFE, MuRoldanaS, MuRoldanaD, MuAnel, MuFecho, 
            MuCaixaHermetica, MuBarraAterramento, MuTuboAterramento, MuAntena, MuRadio, TrPing, TrTracert, TrVelocidade, TrCaboCliente, TrPontoRede,
            TrRJ45, TrVerificPlacaRede, TrVerificDHCP, TrConfigDiscador, TrConfigRoteador, TrConfigRadio, TrHabilitacaoServico, TrInformacaoChuvas,
            TrTelefoneSuporte, TrMudancaPortaBackbone, TrMudancaPortaCliente, TrTreinamentoCliente )
                    Values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
$sql->bind_param('iiissssssssssssssssssssssssssssssssssssss', $cod_os, $cod_usuario, $cod_cliente, $NomeCliente, $DataOs, $Hora, $DescProbl, //7
                    $Tp_Instalacao, $MuCaboCliente, $MuCaboBackBone, $MuRJ45, $MuEmendaBargoa, $MuTomada, $MuBenjamimAdaptador, $MuEsticadorCaboFE,  //8
                    $MuRoldanaS, $MuRoldanaD, $MuAnel, $MuFecho, $MuCaixaHermetica, $MuBarraAterramento, $MuTuboAterramento, $MuAntena, $MuRadio, $TrPing, //10
                    $TrTracert, $TrVelocidade, $TrCaboCliente, $TrPontoRede, $TrRJ45, $TrVerificPlacaRede, $TrVerificDHCP, $TrConfigDiscador, //8
                    $TrConfigRoteador, $TrConfigRadio, $TrHabilitacaoServico, $TrInformacaoChuvas, $TrTelefoneSuporte, $TrMudancaPortaBackbone, //6
                    $TrMudancaPortaCliente, $TrTreinamentoCliente); //2
$sql->execute();
$sql->close();
?>


I have not put all the variables to summarize and so the purpose of this post is to pass $ _Session to the Form and save it to the bank.

    
asked by anonymous 03.09.2014 / 21:02

2 answers

3

Update

I was reviewing a block of code and I remembered a combination of http_build_query and parse_str that may be useful for you.

$_SESSION['session.A'] = 'Meu valor para A';
$_SESSION['session.B'] = 'Meu valor para B';
$build = http_build_query( $_SESSION );

$build will be a sting with: session.A = My + value + for + A & session.B = My + value + for + B

parse_str( $build , $parse );
print_r( $parse );

$parse returns an array: array ('session_A' = & 'My value for A', 'session_B' => 'My value for B') >

* I did not want to update, but it's still a way. Although you can get the same result, json_encode and serialize are still more recommended.

You can write in two ways, using json_encode and serialize , see below:

$_SESSION['name'] = 'meu nome';

Using json_encode

// output: {"name":"meu nome"}
$json = json_encode( $_SESSION );

// parâmetro TRUE retorna um array
// output: array( 'name' => 'meu nome' )
json_decode( $json , true );

// parâmetro stdClass retorna um onjeto stdClass
// output: stdClass Object $name -> 'meu nome'
json_decode( $json , false );

Using serialize

// output: a:1:{s:4:"name";s:8:"meu nome";}
$serialize = serialize( $_SESSION );

// output: array( 'name' => 'meu nome' )
unserialize( $serialize );
    
03.09.2014 / 23:24
0

Try using serialize if you really need to save this in the same way you get link

I'd rather save this in separate value and recover later.

    
03.09.2014 / 21:08