Jump to content

Data truncated for column.......


BrotherLogic

Recommended Posts

  $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")';
[code]$insertfundquery = 'INSERT INTO longterm( fid, fundname, starrating, firstyear, thirdyear, fifthyear, tenthyear, fifthteenyear)
VALUES ("", "$fundname", "$starrating","$firstyear", "$thirdyear", "$fifthyear","$tenthyear","$fifthteenyear")';[/code]
You guys, simple
he 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 do

Thats ofcourse not all but still a little or else you had come up with this error later
@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]
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")
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]
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
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.