D
D
dexering2021-12-15 21:25:27
Python
dexering, 2021-12-15 21:25:27

Why does a database entry error occur?

The code:

The code
import pymysql

conn = pymysql.connect(host=host, port=port, user=user, passwd=password, db=mydb)
cursor = conn.cursor()

us = str(input('username: '))
pd = str(input('password: '))
em = str(input('email: '))
jd = str(input('join date: '))


cursor.execute('''INSERT OR IGNORE INTO users (username, password, email, join_date) 
                   VALUES (%s, %s, %s, %s)''',
                   ( str(us),
                     str(pd),
                     str(em),
                     str(jd),
                   )
               )


conn.commit()
cursor.close()
conn.close()


Mistake:

Mistake
pymysql.err.ProgrammingError: (1064, "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 'OR IGNORE INTO users (username, password, email, join_date) \n                   ' at line 1")


Please help, I've been suffering for two days now

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LXSTVAYNE, 2021-12-15
@dexering

Perhaps this will help:

cursor.execute('''INSERT OR IGNORE INTO users (username, password, email, join_date) VALUES (%s, %s, %s, %s)''',
                   ( str(us),
                     str(pd),
                     str(em),
                     str(jd),
                   )
               )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question