nitation Posted July 1, 2008 Share Posted July 1, 2008 Hello people, I am having problems with the comma sign in the amount field. I have a figure in my amount field that looks like this; 7500004 when i try to transfer a sum that looks like 750,0004, it will only calculate all the figures before the comma. I wanna know if i have an error in my database or what. my table looks like this amount varchar(255); do i need to change the column type to something like FLOAT, DECIMAL or what. Thanks in advance Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Since amount is a varchar, you need to use single quotes around that value in the SQL: "INSERT INTO Table (amount) VALUES ('750,0004');"; Quote Link to comment Share on other sites More sharing options...
nitation Posted July 1, 2008 Author Share Posted July 1, 2008 @ lemmin i am inserting the amount using a form. How do i do it Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 I would assume that the file referred to by the action property of that form would have an SQL string that enters the number into the database. If you can find that and post it (or just the code for the referred page) I could see if something needs to be changed. Quote Link to comment Share on other sites More sharing options...
nitation Posted July 1, 2008 Author Share Posted July 1, 2008 This is the sql query to insert to the database include ("db.php"); $sqlsub=mysql_query("insert into account_activity(userid,AccountSelector,amount_to_send)values('$afso_userid','$AccountSelector','$amount')"); Do i need to provide anything else? Quote Link to comment Share on other sites More sharing options...
Wolphie Posted July 1, 2008 Share Posted July 1, 2008 Just try this and see if it gives you an error in regards to what the problem is. $query = "INSERT INTO `account_activity` ( `userid`, `AccountSelector`, `amount_to_send` ) VALUES ( ' $afso_userid', '$AccountSelector', '$ammount' )"; $result = mysql_query($query) or trigger_error(mysql_error()); Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Well it looks like there are single quotes which would make me think that the calculations are being done in php but the number isn't being converted from a string. You might be able to fix it where the calculation is, but the best way would probably be to just remove the commas before putting the string in the database. I think this would work: $sqlsub=mysql_query("insert into account_activity(userid,AccountSelector,amount_to_send)values('$afso_userid','$AccountSelector','".preg_replace(",", "", $amount)."')"); Quote Link to comment Share on other sites More sharing options...
nitation Posted July 1, 2008 Author Share Posted July 1, 2008 @ lemmin Thank you, i got my codes right 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.