1

Can you please have a look at this query,which is causing count doesn't match error,but i have same number of columns and values.

This is my table structure

ID| name1 | name2 | name3 | name4 | name5 | table_name

insert into `tnames` (`'name1','name2','name3','name4','name5','table_name'`)
values ('test','test','test','test','test','table_name')
Khirad Zahra
  • 843
  • 2
  • 17
  • 42
  • 1
    remove the backticks from name1 column and table_name column – Ankit Agrawal Sep 25 '17 at 07:19
  • Removing backticks also not working @AnkitAgrawal – Khirad Zahra Sep 25 '17 at 07:21
  • @KhiradBanu do you get a new error after removing the back-ticks or is it the same error? – Kevin Kloet Sep 25 '17 at 07:26
  • Yes,there is a syntax error by removing those back ticks @KevinKloet – Khirad Zahra Sep 25 '17 at 07:27
  • 2
    this is probably caused by the column with the underscore, replace the single quotes with back-quotes in the table column names like this `insert into \`tnames\`(\`name1\`,\`name2\`,\`name3\`,\`name4\`,\`name5\`,\`table_name\`) values ('test','test','test','test','test','table_name') – Kevin Kloet Sep 25 '17 at 07:34
  • 1
    As @KevinKloet stated, replace the quotes with back-ticks for the column names. Your initial error comes from enclosing the entire set of columns inside back-ticks - essentially telling the DB engine that you are inserting into one column, not six. – Peter Abolins Sep 25 '17 at 08:01

3 Answers3

2

try this

insert into `tnames` (`name1`,`name2`,`name3`,`name4`,`name5`,`table_name`)
values ('abc','xyz','pqr','erg',)
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
1

Hi check Mysql insert query syntax https://www.w3schools.com/sql/sql_insert.asp

Insert query don't accept single/double quotes for field names

insert into `tnames` (`'name1','name2','name3','name4','name5','table_name'`)
values ('test','test','test','test','test','table_name') // Unnecessary single quotes for field names 

So please change to like this

insert into `tnames` (name1,name2,name3,name4,name5,table_name)
    values ('test','test','test','test','test','table_name')

This will work

KMS
  • 566
  • 4
  • 16
-1

intenta quitar las comillas, ya que indican una sola entrada de datos:

ID| name1 | name2 | name3 | name4 | name5 | table_name

insert into tnames values
(null, 'name1','name2','name3','name4','name5','table_name')
//null is by the column id, if you have it as auto increment you will not have problem


//also verify the type of data that accepts the column in your database

I hope it works for you, good luck

//si hablas español, traduce tambien los comentarios para que comprendas mejor