0

I am having a small problem updating my cart because of "undefined index:quantity message coming up on my text box.On the last line of my code. what is wrong with the code? Any kind consideration will be highly appreciated.

    function edit_quantity(){
      if(isset($_POST['update_cart'])){
        $quantity=$_POST['quantity'];
          $sql3="UPDATE Shopcart set qty='$quantity'";
          $sql3_run=mysqli_query($conn,$sql3);
         $_SESSION['quantity']=$quantity;
         $total=$total*$quantity;
        }
       echo $_SESSION['quantity'];

      }
saurabh kamble
  • 1,510
  • 2
  • 25
  • 42

2 Answers2

0

i see you dont have session_start();

put it somewhere before you use $_SESSION

edit:

your code might not enter the if block and would not set the quantity session. That's why you are having an Undefied index error move the echo statement inside the if block so that it will echo when your quantity session is set.

John Pangilinan
  • 953
  • 1
  • 8
  • 25
  • Thanks for your swift reply, I have a session _start on the top of the php page. – Francis Jan 02 '16 at 01:33
  • moving the echo statement to when the session statement was set cleared the error. Thank you for your swift response much appreciated! – Francis Jan 02 '16 at 02:34
0

This error is because the POST data does not have a quantity value. You are only checking for an update_cart post value before proceeding to update the session.

As others have mentioned, there is also a serious sql injection problem with your code which you should fix.

harryg
  • 23,311
  • 45
  • 125
  • 198