一切工作正常,但現在發生了什麼,我不能說。實際上mysql不會存儲任何浮點值,並且所有其他值(如integer,varchar等)都可以接受。我發佈了一部分代碼。爲什麼mysql丟棄float值?
以.php
$que_cinstructors = "
INSERT INTO
course_instructors
(usn, i1, i2, i3, i4, i5, i6, i7, i8, i9)
VALUES
(:usn, :i1, :i2, :i3, :i4, :i5, :i6, :i7, :i8, :i9)";
$query_params3 = array(':usn' => $_POST['usn'],
':i1' => $_POST['i1'],
':i2' => $_POST['i2'],
':i3' => $_POST['i3'],
':i4' => $_POST['i4'],
':i5' => $_POST['i5'],
':i6' => $_POST['i6'],
':i7' => $_POST['i7'],
':i8' => $_POST['i8'],
':i9' => $_POST['i9']
);
$statement3 = $db->prepare($que_cinstructors);
$result3 = $statement3->execute($query_params3);
$que_ccredits = "
INSERT INTO
course_credits
(usn, c1, c2, c3, c4, c5, c6, c7, c8, c9, total)
VALUES (:usn, :c1, :c2, :c3, :c4, :c5, :c6, :c7, :c8, :c9, :total)";
$query_params4 = array(':usn' => $_POST['usn'],
':c1' => $_POST['c1'],
':c2' => $_POST['c2'],
':c3' => $_POST['c3'],
':c4' => $_POST['c4'],
':c5' => $_POST['c5'],
':c6' => $_POST['c6'],
':c7' => $_POST['c7'],
':c8' => $_POST['c8'],
':c9' => $_POST['c9'],
':total' => $_POST['total']
);
$statement4 = $db->prepare($que_ccredits);
$result4 = $statement4->execute($query_params4);
查詢從上面兩個查詢第一個存儲的名稱,其細。但第二個是存儲浮點值。在這裏,我從會話變量中獲取usn。第一個插入沒問題,但第二個沒有存儲。從.SQL
數據庫
CREATE TABLE IF NOT EXISTS `course_instructors` (
`i_id` int(11) NOT NULL AUTO_INCREMENT,
`usn` varchar(7) NOT NULL,
`i1` varchar(50) NOT NULL,
`i2` varchar(50) NOT NULL,
`i3` varchar(50) NOT NULL,
`i4` varchar(50) NOT NULL,
`i5` varchar(50) NOT NULL,
`i6` varchar(50) NOT NULL,
`i7` varchar(50) NOT NULL,
`i8` varchar(50) NOT NULL,
`i9` varchar(50) NOT NULL,
PRIMARY KEY (`i_id`),
UNIQUE KEY `usn` (`usn`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE IF NOT EXISTS `course_credits` (
`c_id` int(11) NOT NULL AUTO_INCREMENT,
`usn` varchar(7) NOT NULL,
`c1` float NOT NULL,
`c2` float NOT NULL,
`c3` float NOT NULL,
`c4` float NOT NULL,
`c5` float NOT NULL,
`c6` float NOT NULL,
`c7` float NOT NULL,
`c8` float NOT NULL,
`c9` float NOT NULL,
`total` float NOT NULL,
PRIMARY KEY (`c_id`),
UNIQUE KEY `usn` (`usn`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
一切工作正常。我正在與項目的其他部分一起工作,今天當我嘗試提交然後我遇到了這個問題。這讓我瘋狂......請幫助 而文本字段名稱是正確的。
究竟是如何「丟棄」截斷值? 3.1415變成3?完全不正確的值? (3.1415變成17)。你結束了空值?你是**確定**它是MySQL做到這一點,而不是你的代碼?您是否已驗證$ _POST值是否正確? –
您確定您在輸入中使用了正確的小數點嗎? – DCoder
插入數據時是否有警告? O_o –