Laravel - SQL - SQLSTATE[01000]: Warning: 1265 Data truncated for column 'nsfw' at row 1

Viewed 47453

I'm trying to safe some data in my database and get the following error:

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'nsfw' at row 1

The nsfw column has a 0 as a standart value. Thats my table:

phpmyadminscreenshot

The nsfw column is also in the models $fillable array.

I want to detect if a checkbox is checked. If it is checked, nsfw should be 1. If it's not, nsfw should be 0.

Thats the checkbox HTML code:

 <div class="form-group">
             <label for="nsfw" class="control-label">NSFW</label>
             <br>
             <input type="checkbox" name="nsfw">
  </div>

And thats the controller code:

 if (Input::get('nsfw')) {
       $nsfw = true;
 } else {
       $nsfw = false;
 }

 // dd($nsfw) gives me true or 
 //false back, depending if the checkbox is checked or not

 $thread = new Thread();
 $thread->name = Input::get('thread-name');
 $thread->description = Input::get('thread-desc');
 $thread->age_min = Input::get('thread-min-age');
 $thread->age_max = Input::get('thread-max-age');
 if ($nsfw == true) {
     $thread->nsfw = 1;
 } else {
     $thread->nsfw = 0;
 }
 $thread->save();

Thanks for your help and sorry for my bad english!

4 Answers

Also, check the database column for spelling mistakes for that, or enum value exists in the col.

The data is truncated because you use a comma (,) when input data, try not to use a comma in the data to be input.

this my error :

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'D01' at row 1 (SQL: insert into mbs (kodepertanyaan, D01, D02, D03, D04, D05, D06, D07) values (drg, 0,7, 0, 0, 0, 0, 0, 0))

I try to input 0,7

Related