enter decimal into db from form.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

enter decimal into db from form.

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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
lafflin
Forum Contributor
Posts: 123
Joined: Thu Jul 26, 2007 6:26 pm

Post 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.
Post Reply