Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. is there any other function that i can use rather than .next()? because it reads only the last query
Forum Updated to NodeBB v4.3 + New Features

is there any other function that i can use rather than .next()? because it reads only the last query

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 711 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on 23 Jan 2017, 03:57 last edited by A Former User
    #1

    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

    J 1 Reply Last reply 23 Jan 2017, 05:21
    0
    • ? A Former User
      23 Jan 2017, 03:57

      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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 23 Jan 2017, 05:21 last edited by jsulm
      #2

      @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()
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      ? 1 Reply Last reply 23 Jan 2017, 08:32
      3
      • J jsulm
        23 Jan 2017, 05:21

        @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()
        
        ? Offline
        ? Offline
        A Former User
        wrote on 23 Jan 2017, 08:32 last edited by
        #3

        @jsulm it will always execute my else statement

        J 1 Reply Last reply 23 Jan 2017, 08:35
        0
        • ? A Former User
          23 Jan 2017, 08:32

          @jsulm it will always execute my else statement

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 23 Jan 2017, 08:35 last edited by
          #4

          @Gelo Then check the data you get for USERNAME, PASSWORD and from the db.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          2/4

          23 Jan 2017, 05:21

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved