问题
def Register(self):
QMessageBox.about(self,"Successfully Saved Data",'saved')
username = self.lineEdit.text()
pwd = self.lineEdit_2.text()
cursor = self.connek.cursor()
into_data = 'insert into login(username,passwrd) values(%s,%s);'
db_column = (username , pwd)
cursor.execute(into_data, db_column)
self.connek.commit()
cursor1 = self.connek.cursor()
cursor1.execute('select username, passwrd from login;')
x = cursor1.fetchall()
print(x)
login.show()
reg.hide()
cursor.close()
Hi guys I'm new to Pyqt5 and MySql my sole goal is to put a rejection message if there is an existing account in the database however I don't have enough knowledge to do it so. will you help me please? thank you!
回答1:
If username isn't a unique or primary key of the login table, make it one.
ALTER TABLE login ADD UNIQUE KEY (username);
or
ALTER TABLE login ADD PRIMARY KEY (username);
When you attempt an insert, look at the result for the duplicate key error. In that case a user already exists.
来源:https://stackoverflow.com/questions/60629682/register-accountwindow-rejection-when-value-is-on-database-mysql