NameError and AttributeError while inserting variables in SQLite3 table with Tkinter?












1















I wanted to make a text-file manager, but I'm stuck at the login/sign-up page. My program takes inputs (Name, Last name, username and password) from the user and stores them all in a database. However, I can't retrieve the said data because every time I try, I end up with either a NameError (uname not defined (uname is global everywhere)) or an AttributeError (str object does not have .get()). Here is a small piece of my code:



def login_check():
global password, uname
checkpass=cur.execute("SELECT Password from Sample WHERE Uname = (?);",(uname.get()),)
conn.commit;
if checkpass==password.get():
mainscreen()
else:
mb.showerror('Login Failed','Username or Password incorrect. Please retry.')


Here's how I've taken the entry for the username in a different function:



uname=Entry(spp)
uname.grid(row=3, column=1)
cur.execute("insert into Sample values (?, ?, ?, ?)", (fname.get(), lname.get(), uname.get(), password.get()));


The program ran well and didn't show the errors only until recently. I can't add the entire code here because it is too large, but I'd really appreciate it if someone could suggest what I could do to improve it. Thanks!










share|improve this question



























    1















    I wanted to make a text-file manager, but I'm stuck at the login/sign-up page. My program takes inputs (Name, Last name, username and password) from the user and stores them all in a database. However, I can't retrieve the said data because every time I try, I end up with either a NameError (uname not defined (uname is global everywhere)) or an AttributeError (str object does not have .get()). Here is a small piece of my code:



    def login_check():
    global password, uname
    checkpass=cur.execute("SELECT Password from Sample WHERE Uname = (?);",(uname.get()),)
    conn.commit;
    if checkpass==password.get():
    mainscreen()
    else:
    mb.showerror('Login Failed','Username or Password incorrect. Please retry.')


    Here's how I've taken the entry for the username in a different function:



    uname=Entry(spp)
    uname.grid(row=3, column=1)
    cur.execute("insert into Sample values (?, ?, ?, ?)", (fname.get(), lname.get(), uname.get(), password.get()));


    The program ran well and didn't show the errors only until recently. I can't add the entire code here because it is too large, but I'd really appreciate it if someone could suggest what I could do to improve it. Thanks!










    share|improve this question

























      1












      1








      1








      I wanted to make a text-file manager, but I'm stuck at the login/sign-up page. My program takes inputs (Name, Last name, username and password) from the user and stores them all in a database. However, I can't retrieve the said data because every time I try, I end up with either a NameError (uname not defined (uname is global everywhere)) or an AttributeError (str object does not have .get()). Here is a small piece of my code:



      def login_check():
      global password, uname
      checkpass=cur.execute("SELECT Password from Sample WHERE Uname = (?);",(uname.get()),)
      conn.commit;
      if checkpass==password.get():
      mainscreen()
      else:
      mb.showerror('Login Failed','Username or Password incorrect. Please retry.')


      Here's how I've taken the entry for the username in a different function:



      uname=Entry(spp)
      uname.grid(row=3, column=1)
      cur.execute("insert into Sample values (?, ?, ?, ?)", (fname.get(), lname.get(), uname.get(), password.get()));


      The program ran well and didn't show the errors only until recently. I can't add the entire code here because it is too large, but I'd really appreciate it if someone could suggest what I could do to improve it. Thanks!










      share|improve this question














      I wanted to make a text-file manager, but I'm stuck at the login/sign-up page. My program takes inputs (Name, Last name, username and password) from the user and stores them all in a database. However, I can't retrieve the said data because every time I try, I end up with either a NameError (uname not defined (uname is global everywhere)) or an AttributeError (str object does not have .get()). Here is a small piece of my code:



      def login_check():
      global password, uname
      checkpass=cur.execute("SELECT Password from Sample WHERE Uname = (?);",(uname.get()),)
      conn.commit;
      if checkpass==password.get():
      mainscreen()
      else:
      mb.showerror('Login Failed','Username or Password incorrect. Please retry.')


      Here's how I've taken the entry for the username in a different function:



      uname=Entry(spp)
      uname.grid(row=3, column=1)
      cur.execute("insert into Sample values (?, ?, ?, ?)", (fname.get(), lname.get(), uname.get(), password.get()));


      The program ran well and didn't show the errors only until recently. I can't add the entire code here because it is too large, but I'd really appreciate it if someone could suggest what I could do to improve it. Thanks!







      python database sqlite tkinter sqlite3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 19:43









      Soumya MukhijaSoumya Mukhija

      96




      96
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This a workaround from me to check if the data inserted in the entry is valid data in db. Since you didn't paste column name for password i did it P_word change that to password column name in your table.



          This will check if the data is valid before it will open the main window if not messagebox will pop up. Make sure you close the login window after opening main window.



          def login_check():
          global password, uname

          con = sqlite3.connect("database_name.db") # your database should be name
          cur = con.cursor()

          attempt = ("SELECT * FROM Password WHERE Uname=? AND P_word=?") # column to check name n password
          cur.execute(attempt, (uname.get(), password.get()))
          rows = cur.fetchall()

          if rows:
          mainscreen()
          else:
          mb.showerror('Login Failed','Username or Password incorrect. Please retry.')





          share|improve this answer
























          • You can comment if you need any assistant.

            – AD WAN
            Nov 23 '18 at 6:12











          • @Soumya Mukhija if the answer solves your problem make sure you tick it as reference for future coders.

            – AD WAN
            Nov 23 '18 at 9:29











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437228%2fnameerror-and-attributeerror-while-inserting-variables-in-sqlite3-table-with-tki%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          This a workaround from me to check if the data inserted in the entry is valid data in db. Since you didn't paste column name for password i did it P_word change that to password column name in your table.



          This will check if the data is valid before it will open the main window if not messagebox will pop up. Make sure you close the login window after opening main window.



          def login_check():
          global password, uname

          con = sqlite3.connect("database_name.db") # your database should be name
          cur = con.cursor()

          attempt = ("SELECT * FROM Password WHERE Uname=? AND P_word=?") # column to check name n password
          cur.execute(attempt, (uname.get(), password.get()))
          rows = cur.fetchall()

          if rows:
          mainscreen()
          else:
          mb.showerror('Login Failed','Username or Password incorrect. Please retry.')





          share|improve this answer
























          • You can comment if you need any assistant.

            – AD WAN
            Nov 23 '18 at 6:12











          • @Soumya Mukhija if the answer solves your problem make sure you tick it as reference for future coders.

            – AD WAN
            Nov 23 '18 at 9:29
















          0














          This a workaround from me to check if the data inserted in the entry is valid data in db. Since you didn't paste column name for password i did it P_word change that to password column name in your table.



          This will check if the data is valid before it will open the main window if not messagebox will pop up. Make sure you close the login window after opening main window.



          def login_check():
          global password, uname

          con = sqlite3.connect("database_name.db") # your database should be name
          cur = con.cursor()

          attempt = ("SELECT * FROM Password WHERE Uname=? AND P_word=?") # column to check name n password
          cur.execute(attempt, (uname.get(), password.get()))
          rows = cur.fetchall()

          if rows:
          mainscreen()
          else:
          mb.showerror('Login Failed','Username or Password incorrect. Please retry.')





          share|improve this answer
























          • You can comment if you need any assistant.

            – AD WAN
            Nov 23 '18 at 6:12











          • @Soumya Mukhija if the answer solves your problem make sure you tick it as reference for future coders.

            – AD WAN
            Nov 23 '18 at 9:29














          0












          0








          0







          This a workaround from me to check if the data inserted in the entry is valid data in db. Since you didn't paste column name for password i did it P_word change that to password column name in your table.



          This will check if the data is valid before it will open the main window if not messagebox will pop up. Make sure you close the login window after opening main window.



          def login_check():
          global password, uname

          con = sqlite3.connect("database_name.db") # your database should be name
          cur = con.cursor()

          attempt = ("SELECT * FROM Password WHERE Uname=? AND P_word=?") # column to check name n password
          cur.execute(attempt, (uname.get(), password.get()))
          rows = cur.fetchall()

          if rows:
          mainscreen()
          else:
          mb.showerror('Login Failed','Username or Password incorrect. Please retry.')





          share|improve this answer













          This a workaround from me to check if the data inserted in the entry is valid data in db. Since you didn't paste column name for password i did it P_word change that to password column name in your table.



          This will check if the data is valid before it will open the main window if not messagebox will pop up. Make sure you close the login window after opening main window.



          def login_check():
          global password, uname

          con = sqlite3.connect("database_name.db") # your database should be name
          cur = con.cursor()

          attempt = ("SELECT * FROM Password WHERE Uname=? AND P_word=?") # column to check name n password
          cur.execute(attempt, (uname.get(), password.get()))
          rows = cur.fetchall()

          if rows:
          mainscreen()
          else:
          mb.showerror('Login Failed','Username or Password incorrect. Please retry.')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 6:12









          AD WANAD WAN

          8701216




          8701216













          • You can comment if you need any assistant.

            – AD WAN
            Nov 23 '18 at 6:12











          • @Soumya Mukhija if the answer solves your problem make sure you tick it as reference for future coders.

            – AD WAN
            Nov 23 '18 at 9:29



















          • You can comment if you need any assistant.

            – AD WAN
            Nov 23 '18 at 6:12











          • @Soumya Mukhija if the answer solves your problem make sure you tick it as reference for future coders.

            – AD WAN
            Nov 23 '18 at 9:29

















          You can comment if you need any assistant.

          – AD WAN
          Nov 23 '18 at 6:12





          You can comment if you need any assistant.

          – AD WAN
          Nov 23 '18 at 6:12













          @Soumya Mukhija if the answer solves your problem make sure you tick it as reference for future coders.

          – AD WAN
          Nov 23 '18 at 9:29





          @Soumya Mukhija if the answer solves your problem make sure you tick it as reference for future coders.

          – AD WAN
          Nov 23 '18 at 9:29


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437228%2fnameerror-and-attributeerror-while-inserting-variables-in-sqlite3-table-with-tki%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin