Page 1 of 1

enter decimal into db from form.

Posted: Sat Dec 29, 2007 10:45 am
by lafflin
Hello all, I am having an issue with a script that I am writting, befor I get into the details though, I just want to thank all of you who have helped me in the past. There are many of you and you all make this the best PHP forum in existence.

My issue, and I'm sure this is quite remedial, is that I am trying to enter into a text box, a decimal amount. The input gets inserted into a MySQL DB where the data type is decimal 2,2 (this has been set up using phpMyAdmin). but after inserting the amount xx.xx I end up with 0.99 in my DB.
var_dump tells me that I am entering in a string(5), but even after trying to use settype($x,float) I am still getting the same result. I simply don't know what I am doing. I will hold off on posting my code as I have a feeling that many of you know why this is happeneing without having to even see it, but if necessary I will post my code as well.

Thank you for any input given.

Posted: Sat Dec 29, 2007 1:57 pm
by califdon
Your data type of Decimal(2,2) limits the total number of digits to 2. You apparently want to be able to enter amounts up to 99.99, right? That would be Decimal(4,2). Check out http://dev.mysql.com/doc/refman/5.1/en/ ... anges.html

Posted: Sat Dec 29, 2007 3:37 pm
by lafflin
ah ha! thank you so much! I'll try it and report back to this post, but I'm sure that is the problem.