Jump to content

Recommended Posts

The total cost part of my basket works fine when I add products individualy. But if I change the quantity of products already in the basket it goes awol.

 

eg.

 

Product:          price    extended price

1 x computer    £520        £520

1 x computer    £520        £520

                          Total =£1,040.00

 

 

Product:          price    extended price

2 x computer    £520        £1,040.00

1 x computer    £520        £520

                          Total =£521.00

 

What am I doing wrong??

 

The code is:

   <?php
           while ($row = mysql_fetch_array($results)) {
               extract ($row);
               $prod = "SELECT * FROM products WHERE id =
               '$prodnum'";
               $prod2 = mysql_query($prod);
               $prod3 = mysql_fetch_array($prod2);
               extract ($prod3);
               echo "<td><form method = 'POST' action='change.php'>
                    <input type='hidden' name='prodnum'
                        value='$prodnum'>
                    <input type='hidden' name='sessid'
                        value='$sessid'>
                    <input type='hidden' name='hidden'
                        value='$hidden'>
                    <input type='text' name='qty' size='2'
                        value='$quan'>";
               echo "</td>";
               echo "<td>";
		   echo $type;
		   echo "</td>"; 
               echo "<td>";
               echo $name;
               echo "</td></a>";
               echo "<td align='right'>";
               echo $price;
               echo "</td>";
               echo "<td align='right'>";
          //get extended price
               $extprice = number_format($price * $quan, 2);
               echo $extprice;
               echo "</td>";
               echo "<td>";
               echo "<input type='submit' name='Submit'
                         value='Change Qty'>
                      </form></td>";
               echo "<td>";
               echo "<form method = 'POST' action='delete.php'>
                    <input type='hidden' name='prodnum'
                           value='$prodnum'>
                    <input type='hidden' name='qty' value='$quan'>
                    <input type='hidden' name='hidden'
                           value='$hidden'>
                    <input type='hidden' name='sessid'
                           value='$sessid'>";
               echo "<input type='submit' name='Submit'
                           value='Delete Item'>
                      </form></td>";
               echo "</tr>";
          //add extended price to total
               $total = $extprice + $total;

               }
?>
<tr>
<td colspan='4' align='right'>Your total is:</td>
<td align='right'>£<?php echo number_format($total, 2) ?></td>
<td></td>
<td></td>
</tr>
</table>

 

 

Link to comment
https://forums.phpfreaks.com/topic/65312-more-basket-problems/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.