BrotherLogic Posted August 14, 2006 Share Posted August 14, 2006 I am trying some code in PHP and when I try to INSERT values into a MySQL database my program dies.When I call mysql_error() it reads "Data truncated for column fundname at row 1"Anybody know what a possible cause to the problem is?Thanks EVERYONE Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/ Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 Please post the MySQL query that produces this error. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74316 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 $createtablequery = 'CREATE TABLE longterm( '. 'fid INT NOT NULL AUTO_INCREMENT, '. 'fundname VARCHAR(75) NOT NULL, '. 'starrating VARCHAR(60) NOT NULL, '. 'firstyear FLOAT, '. 'thirdyear FLOAT, '. 'fifthyear FLOAT, '. 'tenthyear FLOAT, '. 'fifthteenyear FLOAT, '. 'PRIMARY KEY(fid))'; $insertfundquery = 'INSERT INTO longterm( fundname,'. 'starrating, firstyear, thirdyear,'. 'fifthyear, tenthyear, fifthteenyear)'. 'VALUES ( "$fundname", "$starrating",'. '"$firstyear", "$thirdyear", "$fifthyear",'. '"$tenthyear", "$fifthteenyear")'; Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74324 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 aand the exact error reads: "Data truncated for column 'firstyear' at row" Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74326 Share on other sites More sharing options...
fenway Posted August 14, 2006 Share Posted August 14, 2006 What is the value for $firstyear that you're trying to insert? It obviously doesn't match the column spec. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74340 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 the values are as follows: 7.04 , 1.66, 21.11, 27.35, 0, etc. I am getting the same error with all the values.Thanks for the help everyone. I am a mySQL newbian. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74352 Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 [code]$insertfundquery = 'INSERT INTO longterm( fid, fundname, starrating, firstyear, thirdyear, fifthyear, tenthyear, fifthteenyear) VALUES ("", "$fundname", "$starrating","$firstyear", "$thirdyear", "$fifthyear","$tenthyear","$fifthteenyear")';[/code] Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74425 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 Still not working.I am getting "data truncated for column 'firstyear' at row 1" from mysql_errorand I am getting ERROR #1265 from mysql_errno.Anybody know what the problem might be?Thanks a bunch. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74585 Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 My sql knowledge is rudimentary but I'm wondering if the FLOAT declarations (in your table definition) actually need to give the field definition rather than just 'FLOAT', i.e, FLOAT (5,2) to allow a signed four-figure number and 2 decimal places. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74600 Share on other sites More sharing options...
fenway Posted August 14, 2006 Share Posted August 14, 2006 Perhaps... not sure what the default would be with no (M,D)... post the SHOW CREATE output and you'll see for certain. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74609 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 I've tried the (5,2) in the definition of the table.Still the same error number and error output. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74624 Share on other sites More sharing options...
Chetan Posted August 14, 2006 Share Posted August 14, 2006 You guys, simplehe uses variables in '' $insertfundquery = 'INSERT INTO longterm( fundname,'. 'starrating, firstyear, thirdyear,'. 'fifthyear, tenthyear, fifthteenyear)'. 'VALUES ( "$fundname", "$starrating",'. '"$firstyear", "$thirdyear", "$fifthyear",'. '"$tenthyear", "$fifthteenyear")';Now you know wat to doThats ofcourse not all but still a little or else you had come up with this error later Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74626 Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 @RockingGroudon: I'm assuming the insert query was changed to match my suggestion.To continue, I think we need to see a full error and query message. Change the relevant part of your insert code to this:[code]$insertfundquery = " ... whatever you're using";$result = mysql_query($insertfundquery) or die("Error: ". mysql_error(). " with query ". $insertquery);[/code] Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74630 Share on other sites More sharing options...
Chetan Posted August 14, 2006 Share Posted August 14, 2006 @Andyb - Sorry but I still dont see anywhere anybody giving a code which tells him not to use '' while putting vars in it, not is the use of . to do same here? Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74639 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 Error: Data truncated for column 'firstyear' at row 1 with query INSERT INTO longterm( fundname,starrating, firstyear, thirdyear,fifthyear, tenthyear, fifthteenyear)VALUES ( "$fundname", "$starrating","$firstyear", "$thirdyear", "$fifthyear","$tenthyear", "$fifthteenyear")Error: Data truncated for column 'firstyear' at row 1 with query INSERT INTO longterm( fid, fundname, starrating, firstyear, thirdyear, fifthyear, tenthyear, fifthteenyear) VALUES ("0", "$fundname", "$starrating","$firstyear", "$thirdyear", "$fifthyear","$tenthyear","$fifthteenyear") Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74645 Share on other sites More sharing options...
Chetan Posted August 14, 2006 Share Posted August 14, 2006 See the $ are not considered as variables as i said it should be changed Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74648 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 @RG -- how should it be arranged? I'm lost, I'm a complete newbyyy.Thanks for your help guys. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74658 Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 Ah yes " and ' and all that stuff. Try this insert query (which I ought to have spotted some time back) that avoids the literals RockingGroudon observed.[code]$insertfundquery = "INSERT INTO longterm( fid, fundname, starrating, firstyear, thirdyear, fifthyear, tenthyear, fifthteenyear) VALUES (' ', '$fundname', '$starrating', '$firstyear', '$thirdyear',$fifthyear','$tenthyear','$fifthteenyear')";[/code] Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74660 Share on other sites More sharing options...
Chetan Posted August 14, 2006 Share Posted August 14, 2006 Yup! ~~ forgot my words Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74666 Share on other sites More sharing options...
BrotherLogic Posted August 14, 2006 Author Share Posted August 14, 2006 Oh yeah. You guys rock. Totally my bad... I was getting syntax errors when I took the quotes out because I had the code in the wrong place in my script from testing.Also...I get this error:Error: Out of range value adjusted for column 'fid' at row 1 with query INSERT INTO longterm( fid, fundname, starrating, firstyear, thirdyear, fifthyear, tenthyear, fifthteenyear) VALUES ('', Exposed Fund, '5Star', '7.04', '11.65','7.82','0','0')________________but when I put a zero in for the "fid" VALUE everything works fine.Thanks a Bunch Guys.I really appreciate your help and effort.Jon Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74672 Share on other sites More sharing options...
Chetan Posted August 14, 2006 Share Posted August 14, 2006 You made it with NOT NULL remember, look at the code on the first page, it says fip is NOT NULL Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74689 Share on other sites More sharing options...
fenway Posted August 14, 2006 Share Posted August 14, 2006 Well, your variables aren't interpolating.... I'm assuming that:[code]'VALUES ( "$fundname", "$starrating",'.[/code]should be [code]'VALUES ( "'.$fundname.'", "'.$starrating.'",'.[/code]If PHP is like Perl, nothing in single quotes will be ever be interpolated. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74698 Share on other sites More sharing options...
Chetan Posted August 15, 2006 Share Posted August 15, 2006 Well that was done before~~, fenway, thats what I hav been saying and AndyB corrected it.And did you think you had it NOT NULL as I said Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-74927 Share on other sites More sharing options...
fenway Posted August 15, 2006 Share Posted August 15, 2006 Sorry, I must have missed the second page of posts. ;-)As for NOT NULL, assuming that fid is your PK column, don't even specify it in the column list, and you'll be fine. Link to comment https://forums.phpfreaks.com/topic/17465-data-truncated-for-column/#findComment-75101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.