is there any other function that i can use rather than .next()? because it reads only the last query
-
def Submit_btn(self):
USERNAME = self.username.text()
PASSWORD = self.password.text()self.query = QSqlQuery("SELECT username,password FROM users") while (self.query.next()): user_data = self.query.value(0).toString() pass_data = self.query.value(1).toString() if USERNAME == user_data and PASSWORD == pass_data and USERNAME == "admin" and PASSWORD == "password": print "Login as Adminitrator" elif USERNAME == user_data and PASSWORD == pass_data: print "users mode" else: choice = QMessageBox.question(self,'IMS',"Incorrect username or password!",QMessageBox.Ok) if choice == QMessageBox.Ok: self.ctr = self.ctr + 1 if self.ctr >= 3: choice = QMessageBox.question(self,'IMS',"To many attemps System will terminate") if choice == QMessageBox.Ok: time.sleep(1.5) sys.exit()
i cant access the first and the second data if i have 3 records
-
def Submit_btn(self):
USERNAME = self.username.text()
PASSWORD = self.password.text()self.query = QSqlQuery("SELECT username,password FROM users") while (self.query.next()): user_data = self.query.value(0).toString() pass_data = self.query.value(1).toString() if USERNAME == user_data and PASSWORD == pass_data and USERNAME == "admin" and PASSWORD == "password": print "Login as Adminitrator" elif USERNAME == user_data and PASSWORD == pass_data: print "users mode" else: choice = QMessageBox.question(self,'IMS',"Incorrect username or password!",QMessageBox.Ok) if choice == QMessageBox.Ok: self.ctr = self.ctr + 1 if self.ctr >= 3: choice = QMessageBox.question(self,'IMS',"To many attemps System will terminate") if choice == QMessageBox.Ok: time.sleep(1.5) sys.exit()
i cant access the first and the second data if i have 3 records
@Gelo The problem is not next() the problem is that your code is wrong.
You read user_data and pass_data in the while loop. That means if the loop is finished they will contain the data from last line returned by next().
Should be (the whole stuff must be in the while loop, Python uses indentations to define blocks, so be careful):def Submit_btn(self): USERNAME = self.username.text() PASSWORD = self.password.text() self.query = QSqlQuery("SELECT username,password FROM users") while (self.query.next()): user_data = self.query.value(0).toString() pass_data = self.query.value(1).toString() if USERNAME == user_data and PASSWORD == pass_data and USERNAME == "admin" and PASSWORD == "password": print "Login as Adminitrator" elif USERNAME == user_data and PASSWORD == pass_data: print "users mode" else: choice = QMessageBox.question(self,'IMS',"Incorrect username or password!",QMessageBox.Ok) if choice == QMessageBox.Ok: self.ctr = self.ctr + 1 if self.ctr >= 3: choice = QMessageBox.question(self,'IMS',"To many attemps System will terminate") if choice == QMessageBox.Ok: time.sleep(1.5) sys.exit()
-
@Gelo The problem is not next() the problem is that your code is wrong.
You read user_data and pass_data in the while loop. That means if the loop is finished they will contain the data from last line returned by next().
Should be (the whole stuff must be in the while loop, Python uses indentations to define blocks, so be careful):def Submit_btn(self): USERNAME = self.username.text() PASSWORD = self.password.text() self.query = QSqlQuery("SELECT username,password FROM users") while (self.query.next()): user_data = self.query.value(0).toString() pass_data = self.query.value(1).toString() if USERNAME == user_data and PASSWORD == pass_data and USERNAME == "admin" and PASSWORD == "password": print "Login as Adminitrator" elif USERNAME == user_data and PASSWORD == pass_data: print "users mode" else: choice = QMessageBox.question(self,'IMS',"Incorrect username or password!",QMessageBox.Ok) if choice == QMessageBox.Ok: self.ctr = self.ctr + 1 if self.ctr >= 3: choice = QMessageBox.question(self,'IMS',"To many attemps System will terminate") if choice == QMessageBox.Ok: time.sleep(1.5) sys.exit()
@jsulm it will always execute my else statement
-
@jsulm it will always execute my else statement
@Gelo Then check the data you get for USERNAME, PASSWORD and from the db.