Snatch Posted August 16, 2007 Share Posted August 16, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/65312-more-basket-problems/ Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 My guess is that there is a problem adding together numbers that are formatted differently. Try doing this. $extprice = $price * $quan; echo number_format($extprice, 2); Quote Link to comment https://forums.phpfreaks.com/topic/65312-more-basket-problems/#findComment-326185 Share on other sites More sharing options...
Snatch Posted August 16, 2007 Author Share Posted August 16, 2007 Thanks Lemmin that seems to of fixed it! I actually got the code from a book called beggining php5, my sql and apache by wrox. Seems a bit poor of them? Quote Link to comment https://forums.phpfreaks.com/topic/65312-more-basket-problems/#findComment-326194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.