elentz Posted February 9, 2008 Share Posted February 9, 2008 I have some code that updates a table in a Mysql DB. The table fields are decimal 8,2. If I interrupt the update to the table and echo the variable $formatnet_total I get 2,395.23. If I let it update the table I get 2 in the field. What is happening here? $sql = 'SELECT SUM((vtiger_inventoryproductrel.quantity) * (vtiger_inventoryproductrel.listprice))' . ' from vtiger_inventoryproductrel' . ' where vtiger_inventoryproductrel.id = '.$id.''; $result = mysql_query($sql,$conn); $mytotal = mysql_fetch_row($result); $formatnet_total=number_format($mytotal[0],2,'.',','); $sql4 ="Update vtiger_invoicecf SET cf_602 = '$mitax', cf_610 = '$formatnet_total' where invoicei = '$id'"; $result = mysql_query($sql4) or die(mysql_error() . "<p>With Query<br>$sql4"); Thanks for looking! Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted February 9, 2008 Share Posted February 9, 2008 Does it actually show the "," (comma) when you echo it? Maybe you should strip the comma first and then try inserting... // replace ',' with nothing $formatnet_total = str_replace(",", "", $formatnet_total); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 9, 2008 Share Posted February 9, 2008 Number parsers stop when they find a character that is not part of the data type they are looking for. A coma to separate fields in a number is a human convention not a computer number convention. Only add the coma separator when you display information, not when you store it. Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted February 9, 2008 Share Posted February 9, 2008 I checked the manual.. http://dev.mysql.com/doc/refman/5.0/en/precision-math-decimal-changes.html It doesn't specifically state that the comma would be the escape. But it DOES state that it only accepts integers and a "." It used to accept a "+" or a "-" but those (along with leading zeros) are no longer accepted. It's definitely that comma. Remove it and then you should be all set. Quote Link to comment Share on other sites More sharing options...
elentz Posted February 9, 2008 Author Share Posted February 9, 2008 That ',' was exactly the issue! Thank you very much you made my day! I love this forum! 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.