PHP Shopping Cart duplicate Items when adding to cart using Sessions and Arrays -


help me don't have more solutions. simple want need items separated correctly without duplicating here code

here pic: click on shopping cart pic

order button:

    <?php      session_start();     if(isset($_get['btnbuy']))     {     $_session['cartdesc'][$_session['ctr']] = $_session['desc'][$_session['indexnum']];     $_session['cartprice'][$_session['ctr']] = $_session['price'][$_session['indexnum']];        $_session['cartquant'][$_session['ctr']] = $_get['txtquant'];      $_session['ctr'] = $_session['ctr']+1; //here when duplicate happpens!      header("location: index.php");     } ?> 

here add cart button

  <?php      if(isset($_get['cmdadd0']))         $_session['indexnum'] = 0;     elseif(isset($_get['cmdadd1']))         $_session['indexnum'] = 1;     elseif(isset($_get['cmdadd2']))         $_session['indexnum'] = 2;         echo '<br><br><br><br><br><br><br>';     echo '<form method="get" action="addtocart.php">';     echo '<table border="0" cellpadding="5" cellspacing="0" align="center"><tr>';     echo '<td>' . $_session['desc'][$_session['indexnum']] .'</td>';         echo '<td><input type="text" name="txtquant"></td>';         echo '<td>' . $_session['price'][$_session['indexnum']] .'</td>';         echo '<td><input type="submit" name="btnbuy" value="order"></td>';     echo '</table>';     echo '</form>'; ?> 

here display items

<table border="1" cellpadding="2" cellspacing="2" width="500" align="center">         <tr>             <td>description</td>             <td>quantity</td>             <td>price</td>         </tr>          <?php         if(isset($_session['cartdesc']))         {                                    for($x=0; $x<count($_session['cartdesc']); $x++){                 echo '<tr align="center">';                 echo    '<td>' .$_session['cartdesc'][$x]. '</td>';                 echo    '<td>' .$_session['cartprice'][$x]. '</td>';                 echo    '<td>' .$_session['cartquant'][$x]. '</td>';                   echo '</tr>';             }         }         ?> 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -