Notice: Undefined index:

Asked

Viewed 305 times

-1

I am with several error msg of : Dryness Notice: Undefined index:

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

(When you have a product in the cart( no error appears, pq has data in mysql table) (When I am logged in to the site also no error appears.)

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
}
?>

1 answer

0


You need, as I understand it, to log in to PHP, because if you don’t, you won’t be able to access something like $_SESSION['Something'];

I approved to check the names of the session keys.

<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...
    }
}
?>
  • i already started bro, he can access the good problem is when there is nothing in mysql appears this error: If I add 1 item to the cart it disappears, and log in the login problem also some.

  • I edited the answer for you, to see if it fits. put the count of rows returned from mysql.

  • opa mano I think this is helpful, but I think the problem is in this request because it gave this error: Notice: Undefined index: pedido in C: xampp htdocs skincs logar.php on line 2

  • See the modification in the answer relative to $_SESSION['logged_in'], which was being checked so that if it did not exist, it would return error.

  • you’re the dude dude mds kkkkkkkkkkkkkkkkkkkkk

  • I’ve been racking my brain for such a simple business since yesterday ...'

  • That’s normal buddy, we’ve all suffered a lot one day! Hug and good walk in the code!

  • if you use a similar logic in $sessao = $_SESSION['request']; it would work?

  • Yeah, sure, that’s the best way I know to test sessions. Dig deep!

  • if ($_SESSION['logged_in'] != true){ echo '<a href="log in.php"><li>Login</li></a>'; }Else{ echo $_SESSION['user_name']; } ?>

  • Could you help me with this? When you are not logged in, Undefined appears for the username and I am not being able to use this logic on it.

  • The same name you give to the name in the html input, you recover in the post $_POST["input name here"], then do the isset bid to know if it exists, or ! isset to know if there is no.

  • have you send the code? I did not understand mt well kk.

  • I’m mounting something here, but watch out because you have no username in the code shown here, and yes email and it is it that you recover there in php. Keep testing while I do it.

Show 10 more comments

Browser other questions tagged

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