eco Posted June 14, 2009 Share Posted June 14, 2009 The insert of my data into a table fails on a single column but why?!? Here is where the problem but I just can't figure it out: public function InsertBackupStatus($sqlArray) { self::ConnectToDatabase(); foreach($sqlArray as $nest) { for($i = 0;$i < count($nest);$i+=5) { $this->_sql = "INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',\"" . $nest[$i] . "\",\"" . $nest[$i+1] . "\",\"" . $nest[$i+2] . "\",\"" . $nest[$i+3] . "\",\"" . $nest[$i+4] . "\");"; echo "$this->_sql\n"; $result = mysql_query($this->_sql); if (! $result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } } //for } //foreach self::DisconnectFromDatabase(); } What echo "$this->_sql\n"; returns: INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',"SDE","seniorie","2009-06-13","1218004439609","SUCCESS"); INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',"SDE","seniorie","2009-06-13","1218875528328","SUCCESS"); INSERT INTO tbl_backuplog (`id_bkuplog`,`group`,`login`,`date`,`bkupid`,`status`) VALUES('',"SDE","seniorie","2009-06-13","1216242642656","SUCCESS"); What the database returns is: +------------+----------------+-------------+---------------------+------------+-----------------------+ | id_bkuplog | group | login | date | bkupid | status | +------------+----------------+-------------+---------------------+------------+-----------------------+ | 000024 | SDE | seniorie | 2009-06-13 00:00:00 | 2147483647 | SUCCESS | | 000025 | SDE | seniorie | 2009-06-13 00:00:00 | 2147483647 | SUCCESS | | 000026 | SDE | seniorie | 2009-06-13 00:00:00 | 2147483647 | SUCCESS | +------------+----------------+-------------+---------------------+------------+-----------------------+ Note how all fields are correct except for the db column bkupid where all ids are the same. How can that be when an echo of the SQL query before hand shows the right data. Table structure: DROP TABLE IF EXISTS `tbl_backuplog`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; CREATE TABLE `tbl_backuplog` ( `id_bkuplog` int(6) unsigned zerofill NOT NULL auto_increment COMMENT 'Backup log ID', `group` varchar(30) NOT NULL, `login` varchar(30) NOT NULL, `date` datetime NOT NULL COMMENT 'Backup date', `bkupid` int(13) NOT NULL, `status` varchar(30), PRIMARY KEY (`id_bkuplog`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='table'; SET character_set_client = @saved_cs_client; Does anyone have a clue? Thanks -eco Link to comment https://forums.phpfreaks.com/topic/162131-solved-mysql_query-not-inserting-data-properly/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2009 Share Posted June 14, 2009 You are attempting to put a value into an integer that is larger than what an integer can hold. There is no such thing as INT(13). INT(11) is the most an integer will display. INT[(M)] [uNSIGNED] [ZEROFILL] A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295 If those values are in fact numbers, you would need to use BIGINT. If they are identifying strings (which is how you are treating them in the query, as strings), then you should be using a VARCHAR data type. Link to comment https://forums.phpfreaks.com/topic/162131-solved-mysql_query-not-inserting-data-properly/#findComment-855559 Share on other sites More sharing options...
eco Posted June 14, 2009 Author Share Posted June 14, 2009 Thanks a lot, I was about to change it into a string to see if it solved the problem. Great minds think alike Thanks PFMaBiSmAd Link to comment https://forums.phpfreaks.com/topic/162131-solved-mysql_query-not-inserting-data-properly/#findComment-855560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.