0

how to send 'bit' type data from HTML form to the database.

can we convert it into boolean or something like that. I have tried using type='number' and it didn't work. I get this error:

 ... SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'active' at row 1 (SQL: insert into pg_vendor ... 

here column active is of datatype bit which is either 0 or 1.

I've also used boolean, text, number type and it didn't work.

I'm using Laravel Thanks

3
  • I think I see what you mean, can you intercept the data and translate it into a more acceptable value for your db? Checkbox should be fine for that. And only saving it if it's a 1, just leave it empty if it's none. Make sure columns is nullable. Commented Oct 28, 2017 at 6:41
  • hey there thank you,But i can't change the values of the Db. It breaks the whole work flow of the previously developed system. And checkbox sends data as a string not as a bit type. I want it to be sent as a bit type data. :) Commented Oct 30, 2017 at 7:13
  • have you tried intercepting it with js using $('#the_form').submit(function(){/*grab value and convert here*/}); Commented Nov 1, 2017 at 20:33

1 Answer 1

0

Have you tried with checkbox or radio:

$value = $request->input('bit') ? 1 : 0;

$bit = new Bit;
$bit->bit = $value;
$bit->save();
Sign up to request clarification or add additional context in comments.

1 Comment

sorry, i'm new to laravel. Is there any chance of changing the datatype before POSTing in HTML? Check box and Radio does not work. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.