Register Account(window) Rejection when value is on database (MySQL)

你。 提交于 2021-01-29 14:23:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!