Redeeming values from a SESSION

Asked

Viewed 121 times

0

I’m trying to bring through the <?php include ''.$prod_04.'php'; ?> but I’m not getting back the content registered in $_SESSION['hab_prod_04'].

Already check using <?php echo $prod_04 ?>, and is being recorded in $_SESSION['hab_prod_04'] the desired changes.

I am 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 of $_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 I can’t see the content with the <?php include ''.$prod_04.'php'; ?>, and with the <?php echo $prod_04 ?> I can get.

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

Thanks in advance to everyone for the attention given to my problem.

  • I have the impression that the problem is not even in Session. There is a point missing before php'? Exchange the include for require I can already tell.

  • According to the edition it became clearer that it is a missing point before php' no include.

  • Thanks @Bacco, that was the lack of the point between concatenate and php. Dude I’m two days trying to solve this my Pipino... Rsrsrs... Pure lack of attention on my part... As they say,"Who is out of the problem, sees better the solution". Again, FIGHT.

2 answers

0

With the help of @Bacco, who noticed that the point between concatenate and include php was missing.

Put the code working below.

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

Thank you again @Bacco.

-1

On any page you need to handle the data in one session you should use the function session_start(); to open a session.

This goes so far for the moment you will store the data in one session:

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

When requesting a session data:

<?php
session_start();
echo $_SESSION['user']
?>
  • The session_start(); on every page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.