0

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int primary key, name varchar(100), salary int, doj date)' at line 1

import mysql.connector as mysql
con=mysql.connect(host='localhost',user='root',password='mysqltables',database='school')
cur=con.cursor()
table='INSERT INTO pyStudent(id int primary key, name varchar(100), salary int, doj date)'
cur.execute(table)
for i in range (1,2):
    inpt_id=int(input('Enter employee id',i,'= ' ))
    inpt_name=input('Enter employee name',i,'= ' )
    inpt_sal=int(input('Enter employee salary',i,'= ' ))
    inpt_doj=input('Enter employee joining date',i,'= ' )

    sql = "INSERT INTO pyStudent (id, name, salary, doj) VALUES (%s, %s,%s, %s,%s, %s)"
    val = (inpt_id,inpt_name,inpt_sal,inpt_doj)
    cur.execute(sql, val)
showw='select * from pyStudent'
cur.execute(showw)
temp=cursor.fetchall()
for row in temp:
    print (row)
cur.execute('commit')
1
  • 4
    INSERT INTO pyStudent(id int primary key don't you mean CREATE TABLE pyStudent(id int primary key? Commented Oct 26, 2020 at 9:38

1 Answer 1

0

You adding to many values to your SQL query.

Use (%s, %s, %s, %s) instead of (%s, %s,%s, %s,%s, %s)

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for that correction but i think the error comes due to some different reason You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int(10), name varchar(100), salary int, doj date)' at line 1
Listen, you need to specify values that you are inserting. Here is an example: INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

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.