DarkPrince2005 Posted September 3, 2009 Share Posted September 3, 2009 OK... I've got a really nice shopping cart script, but there seems to be a little problem.... As soon as the Grand total exceeds a thousand it bugs out. echo " <tr> <td> </td><td colspan='4' align='left' class='cart-table'> Your total including shipping is:</td> <td align='center' class='cart-table'>R "; $E=0; $result = mysql_query($query); if (mysql_num_rows($result)==0) { echo "0.00</td><td align='center' valign='center' class='cart-table'>"; } else { while ($row=mysql_fetch_array($result)){ $E +=$row['total']; $total = number_format($E,2); $total1=str_replace(".", "", $total);} echo $total+85; // output: 78 echo ""; $value=str_replace(",","",$total1)+8500; echo "</td><td align='center' valign='center' class='cart-table'>"; } echo "<form method=\"POST\" action=\"modcart.php?action=empty\"> <input type=\"hidden\" name=\"carttemp_hidden\" value=\""; if (isset($carttemp_hidden)) { echo $carttemp_hidden; } echo "\">"; echo "<br /><input type='image' src='images/empty.png' name='empty' value=\"Empty Cart\" onclick=\"this.form.action='modcart.php?action=empty';\"> </form>"; It is suppose to calculate the total and then add 85 for shipping. Can anyone see what I'm doing wrong? Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 3, 2009 Share Posted September 3, 2009 Your trying to str replace a number! It's not a string. Don't use str replace. Instead, use this format number_format($E,2,''); That way you won't have any seperators, so you don't have to take out the comma Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 3, 2009 Author Share Posted September 3, 2009 Ok, I accidently left out a bit of code while ($row = mysql_fetch_array($results)) { echo "<tr height='20px'> <td align='center' valign='center'> <form method='POST' action=''> <input type='hidden' name='modified_hidden' value='$row[cart_id]' class='box'> <input type='text' name='modified_quan' size='2' value='$row[a]' class='box'></td><td align='center' valign='center'><input type='image' name='delete' src='images/change.png' value=\"Change Qty\" onclick=\"this.form.action='modcart.php?action=change';\"> </td> <td align='center' valign='center' class='cart-table'>$row[id]</td> <td align='left' valign='center' class='cart-table'>$row[name]</td> <td align='center' valign='center' class='cart-table'>R $row[price]</td> <td align='center' valign='center' class='cart-table'>R "; //get extended price $extprice = number_format($row['price'] * $row['a'], 2); echo $extprice; echo "</td> <td align='center' valign='center'><input type='image' name='delete' src='images/delete.png' value=\"Delete Item\" onclick=\"this.form.action='modcart.php?action=delete';\"> </form></td>"; echo "</tr>"; //add extended price to total } echo " <tr> <td> </td><td colspan='4' align='left' class='cart-table'> Your total including shipping is:</td> <td align='center' class='cart-table'>R "; $E=0; $result = mysql_query($query); if (mysql_num_rows($result)==0) { echo "0.00</td><td align='center' valign='center' class='cart-table'>"; } else { while ($row=mysql_fetch_array($result)){ $E +=$row['total']; $total = number_format($E,2);} echo $total+85; // output: 78 echo ""; echo "</td><td align='center' valign='center' class='cart-table'>"; } echo "<form method=\"POST\" action=\"modcart.php?action=empty\"> <input type=\"hidden\" name=\"carttemp_hidden\" value=\""; if (isset($carttemp_hidden)) { echo $carttemp_hidden; } echo "\">"; echo "<br /><input type='image' src='images/empty.png' name='empty' value=\"Empty Cart\" onclick=\"this.form.action='modcart.php?action=empty';\"> </form>"; it's still placing a comma in the first extended price.... Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 3, 2009 Share Posted September 3, 2009 Oh, sorry, it should be number_format($E, 2, '.', ''); Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 4, 2009 Author Share Posted September 4, 2009 Ok thats all good and well but now it's posting the amount incorrectly to paygate. Below is my code. the valuue variable basically needs to get a decimal and double zero's added to it. while ($row=mysql_fetch_array($result)){ $E +=$row['total']; $total = number_format($E, 2, '.', '');} echo $total+85; // output: 78 $value=$total+85; Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted September 4, 2009 Share Posted September 4, 2009 add the 85 before number_format(); $E +=$row['total']+85; $total = number_format($E, 2, '.', '');} echo $total; Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 4, 2009 Author Share Posted September 4, 2009 That won't work, as it's adding 85 to every item now, it's only suppose to add 85 once. Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Give this a shot. I haven't been working through your code the whole time, but I'm implementing Garethp's code, MasterACE14's code, and the original script... while adding in a few comments, and cleaning up messy coding. echo " <tr> <td> </td><td colspan='4' align='left' class='cart-table'> Your total including shipping is:</td> "; $E=0; //Not sure what this variable is, or why it's being used (as it doesn't change). $result = mysql_query($query); //Check shopping cart. if (mysql_num_rows($result)==0) { //If shopping cart is empty, echo "<td align='center' class='cart-table'>0.00</td><td align='center' valign='center' class='cart-table'>"; } else { while ($row = mysql_fetch_assoc($result)) { //Loop through result-set. $E += $row['total']; //Add shopping cart prices to $E. $total = number_format($E, 2, '.', ''); //Format total ($E) to $total. echo "<td align='center' class='cart-table'>"; echo $total; echo "</td>"; } } echo " <form method=\"POST\" action=\"modcart.php?action=empty\"> <input type=\"hidden\" name=\"carttemp_hidden\ value=\" "; if (isset($carttemp_hidden)) { echo $carttemp_hidden; } echo " \"> <br /> <input type='image' src='images/empty.png' name='empty' value=\"Empty Cart\" onclick=\"this.form.action='modcart.php?action=empty';\"> </form> "; Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 4, 2009 Author Share Posted September 4, 2009 Nope, not working Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 I'm gonna need more than that. What does it say? Any errors? Is anything echoed at all? Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 4, 2009 Author Share Posted September 4, 2009 Everything is echoing it's just basically not posting correctly to paygate here's the site... www2.storageinstyle.co.za Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 I don't see a problem on the site... Updated code: echo " <tr> <td> </td><td colspan='4' align='left' class='cart-table'> Your total including shipping is:</td> "; $E=0; //Not sure what this variable is, or why it's being used (as it doesn't change). $result = mysql_query($query) or die(mysql_error()); //Check shopping cart. if (mysql_num_rows($result)==0) { //If shopping cart is empty, echo "<td align='center' class='cart-table'>0.00</td><td align='center' valign='center' class='cart-table'>"; } else { while ($row = mysql_fetch_assoc($result)) { //Loop through result-set. $E += $row['total']; //Add shopping cart prices to $E. $total = number_format($E, 2, '.', ''); //Format total ($E) to $total. echo "<td align='center' class='cart-table'>"; echo $total; echo "</td>"; } } echo " <form method=\"POST\" action=\"modcart.php?action=empty\"> <input type=\"hidden\" name=\"carttemp_hidden\ value=\" "; if (isset($carttemp_hidden)) { echo $carttemp_hidden; } echo " \"> <br /> <input type='image' src='images/empty.png' name='empty' value=\"Empty Cart\" onclick=\"this.form.action='modcart.php?action=empty';\"> </form> "; Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 4, 2009 Author Share Posted September 4, 2009 If you actually submit the order and check on Payment site, you'll see the problem with the amount Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 I don't have a valid credit card number... site won't take anything I put in. Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 4, 2009 Author Share Posted September 4, 2009 Just look at the first page...you'll see that instead of giving an amount like 190755.00 it returns 1907.55 Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 4, 2009 Author Share Posted September 4, 2009 It's basically moving the decimal one space forward Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Give this a shot: echo " <tr> <td> </td><td colspan='4' align='left' class='cart-table'> Your total including shipping is:</td> "; $E=0; //Not sure what this variable is, or why it's being used (as it doesn't change). $result = mysql_query($query) or die(mysql_error()); //Check shopping cart. if (mysql_num_rows($result)==0) { //If shopping cart is empty, echo "<td align='center' class='cart-table'>0.00</td><td align='center' valign='center' class='cart-table'>"; } else { while ($row = mysql_fetch_assoc($result)) { //Loop through result-set. $E += $row['total']; //Add shopping cart prices to $E. $E .= 00; //Add trailing zeroes. $total = number_format($E, 2, '.', ''); //Format total ($E) to $total. echo "<td align='center' class='cart-table'>"; echo $total; echo "</td>"; } } echo " <form method=\"POST\" action=\"modcart.php?action=empty\"> <input type=\"hidden\" name=\"carttemp_hidden\ value=\" "; if (isset($carttemp_hidden)) { echo $carttemp_hidden; } echo " \"> <br /> <input type='image' src='images/empty.png' name='empty' value=\"Empty Cart\" onclick=\"this.form.action='modcart.php?action=empty';\"> </form> "; Quote Link to comment 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.