Notice: Undefined index:

-1

I have several error msg of: SecureStore Notice: Undefined index:

basically in my login system when it is not logged in this error appears in shopping cart qnd has no product appears this error.

(When you have a product in the cart (the error does not appear, because it has data in the mysql table) (When I am logged into the site, there is no error.)

code:

<div id="logobuscar">
<div id="wrapperlogo">
<div id="logo"><img src="images/logosecure.png" alt="SecureStore" height="120" width="120"></div>
<div id="buscar">   <?php
                $sessao = $_SESSION['pedido'];
                $consulta = $pdo->prepare("SELECT * FROM carrinho_temporario WHERE temporario_sessao =:ses");
                $consulta -> bindValue(':ses', $sessao);
                $consulta -> execute();
                $linhas = $consulta -> rowCount();
                ?>
                <p class="text-right "><a href="carrinho.php" class="color-white bgcolor-red font-text-light font-weight-heavy car_show">Carrinho(<?= $linhas ?>)</a></p><br>
</form></div>
</div>
</div>  


<?php
if ($_SESSION['logged_in'] != true){
?>


       <form action="login.php" method="post">
        <label for="email">Email: </label>
        <br>
        <input type="text" name="email" id="email">

        <br><br>

        <label for="password">Senha: </label>
        <br>
        <input type="password" name="password" id="password">

        <br><br>

        <input type="submit" value="Entrar">
    </form>
</div>
<?php
}
?>
    
asked by anonymous 27.09.2018 / 13:30

1 answer

0

You need what I realized, is to initialize the session in PHP, because if you do not, you will not be able to access something like $ _SESSION ['SomeCase'];

I checked the session key names.

<div id="logobuscar">
    <div id="wrapperlogo">
        <div id="logo"><img src="images/logosecure.png" alt="SecureStore" height="120" width="120"></div>
        <div id="buscar">   <?php
            if (!session_start())
                session_start();
            $sessao = $_SESSION['pedido'];
            $consulta = $pdo->prepare("SELECT * FROM carrinho_temporario WHERE temporario_sessao =:ses");
            $consulta->bindValue(':ses', $sessao);
            $consulta->execute();
            $linhas = $consulta->fetchall(PDO::FETCH_ASSOC);
            if (count($linhas) > 0) {
                $linhas = $consulta->rowCount();
                ?>
                <p class="text-right "><a href="carrinho.php" class="color-white bgcolor-red font-text-light font-weight-heavy car_show">Carrinho(<?= $linhas ?>)</a></p><br>
                <?php
            }
            ?>
            </form></div>
    </div>
</div>


<?php
if (!isset($_SESSION['logged_in'])) {
    ?>
    <form action="login.php" method="post">
        <label for="email">Email: </label>
        <br>
        <input type="text" name="email" id="email">
        <br><br>
        <label for="password">Senha: </label>
        <br>
        <input type="password" name="password" id="password">
        <br><br>
        <input type="submit" value="Entrar">
    </form>
    </div>
    <?php
} else {
    if (isset($_POST["email"]) && isset($_POST["password"])) {
        // Faz as ações de busca no banco de dados...
    } else {
        // mostra as coisas de login invalido...
    }
}
?>
    
27.09.2018 / 13:43