I'm keep getting 99 when inserting a variable to a decimal

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
stuckne1
Forum Newbie
Posts: 7
Joined: Sat Nov 27, 2010 10:51 am

I'm keep getting 99 when inserting a variable to a decimal

Post by stuckne1 »

I'm attempting to insert into my database. I tried all kinds of values for the txtAmount textbox but I have 99 listed in the database.

I type 100.35 and there is a 99
I type 550.00 and there is a 99

delimiter $$

CREATE TABLE `t_transactions` (
`transaction_id` int(11) NOT NULL AUTO_INCREMENT,
`roommate_id` int(11) NOT NULL,
`date` datetime NOT NULL,
`description` text,
`memo` text,
`amount` decimal(2,0) NOT NULL,
PRIMARY KEY (`transaction_id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1$$

Code: Select all

$roommate_id=$_SESSION["roommate_id"];
      		$date = date("Y-m-d");
      		$description = $_POST['txtDescrip'];
      		$memo = $_POST['txtMemo'];
      		$amount = $_POST['txtAmount'];
      		echo $roommate_id . $date . $description . $memo . $amount;
      	
      		mysql_query("INSERT INTO t_transactions (roommate_id, date, description, memo, amount)
			VALUES ('$roommate_id', '$date', '$description', '$memo', '$amount')") or die(mysql_error());
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: I'm keep getting 99 when inserting a variable to a decim

Post by s.dot »

decimal(2,0) is the problem

The first number is the total amount of numbers you can have, and the second number is the number of decimal places you can have

Try decimal(6, 2) or similar
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
stuckne1
Forum Newbie
Posts: 7
Joined: Sat Nov 27, 2010 10:51 am

Re: I'm keep getting 99 when inserting a variable to a decim

Post by stuckne1 »

perfect! Thank you very much!
Post Reply