Page 1 of 1

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

Posted: Sat Dec 11, 2010 11:52 pm
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());

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

Posted: Sat Dec 11, 2010 11:55 pm
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

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

Posted: Sun Dec 12, 2010 12:04 am
by stuckne1
perfect! Thank you very much!