php - Notice: Undefined index even when using ISSET -


this question has answer here:

i can't figure out why receive error. after pressing add button notice disappears @ refresh.

<?php      session_start();     //session_destroy();     $page ='index.php';      mysql_connect('localhost','root','') or die(mysql_error());     mysql_select_db('cart') or die(mysql_error());        if (isset($_get['add'])) {          $_session['cart_'.$_get['add']] +'1';         }      function products() {      $get = mysql_query('select id, name, description, price products quantity > 0 order id desc');      if (mysql_num_rows($get) == 0 )      {     echo "there no products display";     }         while ($get_row = mysql_fetch_assoc($get)) {             echo '<p>'.$get_row['name'].'<br/>'                       .$get_row['description'].'<br/>'                       .number_format($get_row['price'],2)                       .' <a href="cart.php?add='.$get_row['id'].'">                          add                          </a>                  </p>';              }     }     echo $_session['cart_1'] ?> 

--------and index.php

<?php require 'cart.php' ?> <html> <head> </head> <body>  <?php products(); ?>  </body> </html> 

after executing index.php first time, receive error: notice: undefined index: cart_1 in e:\xamp\htdocs\shopcart\cart.php on line 35

your notice coming echo $_session['cart_1']. , not using isset() there. try like:

if (isset($_session['cart_1'])) {     echo $_session['cart_1']; } else {     echo "session cart_1 not set. here inside session: " . implode(', ',array_keys($_session)); } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -