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")';
Link to comment
Share on other sites

[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
Share on other sites

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
Share on other sites

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
Link to comment
Share on other sites

@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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.