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')
INSERT INTO pyStudent(id int primary key
don't you meanCREATE TABLE pyStudent(id int primary key
? – HoneyBadger