Skip to content
Advertisement

Error converting nvarchar into int… being a number? – Laravel, SQL

I am creating a json to save 2 values of a form that have the same name (data) in order to when 2 rows are saved in the table instead of just one at the same time.

This structure is created like this and cannot be edited.

In principle it works, but in the end it gives me an error that I am not very convinced that it is a Laravel problem or is just SQL, so I do not know where to go.

I have tried to save the value “1” twice to see what it came out, and the following error has come out:

SQLSTATE[22018]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion error when converting the value nvarchar ‘[“1″,”1”]’ to data type int. (SQL: insert into [table_data] ([data]) values ([“1″,”1”]))

The DB and the project itself cannot be simpler, so I don’t know where to go, any idea?.

DB Structure

  • ID (INT, Primary Key, AUTOINCREMENT)
  • Data (INT)

DataController.php

JavaScript

Data.php

JavaScript

StoreDataPost.php

JavaScript

data.blade.php

JavaScript

Advertisement

Answer

The problem is that it’s trying to insert array inside an integer column, Try this instead the code in your store method:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement