error in your SQL syntax - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: error in your SQL syntax (/thread-33528.html) Pages:
1
2
|
error in your SQL syntax - Xuli - May-02-2021 Hi, I am wanting to check if a username already exists. If so a message box will be displayed, if not the username and the rest of the field entries will be stored in the database. However when I tried this, it prints database can’t connect. I tried this without line 65-69 and it works perfectly. RE: Database Connection register form - Yoriz - May-02-2021 Is this a GUI question or a database question? Please show code and a full error traceback that reflects the error. RE: Database Connection register form - Xuli - May-02-2021 (May-02-2021, 12:06 PM)Yoriz Wrote: Is this a GUI question or a database question? How do I post an image here? RE: Database Connection register form - Yoriz - May-02-2021 Please do not paste an image of your code. Please read the following threads. How to ask Smart Questions | What to include in a post | What to NOT include in a post RE: Database Connection register form - Xuli - May-02-2021 // Deleted RE: Database Connection register form - Xuli - May-02-2021 // Deleted RE: Database Connection register form - Xuli - May-02-2021 def register(self): if self.name.get() == "" or self.username.get() == "" or self.password.get() == "": messagebox.showwarning("Alert", "All fields are required!") elif len(self.username.get()) < 3 or len(self.username.get()) > 25: messagebox.showwarning("Alert", "Username must be between 3 and 25 characters!") elif len(self.password.get()) < 6 or len(self.password.get()) > 25: messagebox.showwarning("Alert", "Password must be between 6 and 25 characters!") else: try: db = mysql.connector.connect( host="localhost", username="dbuser01", password="computing", database="geography_quiz" ) db_cursor = db.cursor() db_cursor.execute("SELECT * FROM user_information WHERE Username=%s", self.username.get()) row = db_cursor.fetchone() if row is not None: messagebox.showerror("Error", "Username already exists!") else: db_cursor.execute("INSERT INTO user_information (Full_name, Username, Password) values(%s, %s, %s)", (self.name.get(), self.username.get(), self.password.get() )) db.commit() db.close() messagebox.showinfo("Registration Success!", "Welcome!") except: print("Cannot connect to database") RE: Database Connection register form - Yoriz - May-02-2021 By not checking for a particular exception you have no idea what went wrong add a raise so you can find out what the exception is ... ... ... except: print("Cannot connect to database") raisethen add that add code to deal with that particular exception or fix the unintended error. RE: Database Connection register form - Xuli - May-02-2021 Output: Cannot connect to database Cannot connect to database RE: Database Connection register form - Xuli - May-02-2021 Thanks When I tried this it says No connection could be made because the target machine actively refused it |