Redeem values of a SESSION [duplicate]

0

I'm trying to get through <?php include ''.$prod_04.'php'; ?> but I'm not having return content registered in $_SESSION['hab_prod_04'] .

Already check using <?php echo $prod_04 ?> , and it is being written to $_SESSION['hab_prod_04'] the changes you want.

I'm using the following code to make the change:

    <?php
    $botao=$_POST['enter'];
    if($botao=="Cadastrar"){
        $prod_04 = $_POST["prod_04"];
    if(!empty($prod_04)) {
        $_SESSION['hab_prod_04']["prod_04"] = $prod_04 ;

    echo "<meta http-equiv='refresh' content='0; URL= prod_cad_produtos_5_img.php'>
    <script language='javascript'>
    window.alert('Produto Cadastrado com sucesso!');
    </script>";
    }}
    ?>
    <form method="post">    
    <input type="hidden" name="prod_04" value="produto_04">
    <input type="reset" value="Limpar">
    <input type="submit" value="Cadastrar" name="enter"/>
    </form>

Below code for $_SESSION['hab_prod_04'] :

    if(!isset($_SESSION['hab_prod_04'])){ 

    $prod_04 = 'Vazio'; // Carrega esse conteúdo

    $_SESSION['hab_prod_04']['prod_04']=$prod_04;

    }else if(isset($_SESSION['hab_prod_04'])){

    $prod_04 = $_SESSION['hab_prod_04']["prod_04"];
    }

If friends can help me understand where I'm going wrong, so that I can not see content with <?php include ''.$prod_04.'php'; ?> , and <?php echo $prod_04 ?> I can.

PS: When I use <?php include 'produto_04.php'; ?> , it works.

I thank you all for the attention given to my problem.

    
asked by anonymous 30.09.2016 / 20:02

2 answers

0

With the help of @Bacco, you noticed that there was a missing point between the concatenated and the include php.

Put the code working below.

<?php include ''.$prod_04.'.php'; ?>

Once again thank you very much @Bacco.

    
30.09.2016 / 20:38
-1

On every page you need to manipulate the data in a session you must use the session_start(); function to open a session.

This holds true for the moment when you will store the data in a session:

<?php
session_start();
$_SESSION['user'] = "54151405415345416515";
?>

When it is time to request a session data:

<?php
session_start();
echo $_SESSION['user']
?>
    
30.09.2016 / 20:16