0
PyMySQL Error - No attribute called 'connect'
I'm trying to connect input information to my PHPMyAdmin database, but it keeps saying there is no attribute called connect. Please help. I have installed pymysql correctly and even moved it to directory.
21 Answers
+ 1
+ 1
And Teo Ichim you don't have to move pymysql folder to another directory just keep it at default position i.e., lib(or libs)\site-packages\
+ 1
Yes
0
It was really helpful, I'll try to install it their way next time.
0
Thank you so much, have a nice day.
0
AKSHAY it says the same thing. Please help.
0
I did what it said
0
Teo Ichim did you have installed latest version of pymysql...
0
Through cmd, yes.
0
Teo Ichim
see this again.
https://code.sololearn.com/cY60mkVEIAVb/?ref=app
Now I have installed pymysql on SL system.
If you see that in the last we are getting connection error (because there is no database in localhosr).
There is no problem of connection attribute
0
Okay thank you I'll check it out
0
Let me share my code and you tell me what is wrong with it, please.
Script:
import pymysql as sql
from tkinter import *
from tkinter import ttk,messagebox
from PIL import Image,ImageTk
class Register:
def __init__(self,root):
self.root=root
self.root.title("Registration Window")
self.root.geometry("1350x700+0+0")
self.root.config(bg="white")
self.bg=ImageTk.PhotoImage(file="background.jpg")
bg=Label(self.root,image=self.bg).place(x=250,y=0,relwidth=1,relheight=1)
frame0=Frame(self.root,bg="#15A44B")
frame0.place(x=430,y=250,width=500,height=500)
#Frame
frame1=Frame(self.root,bg="white")
frame1.place(x=850,y=250,width=700,height=500)
title=Label(frame1,text="REGISTER HERE",font=("times new roman",20,"bold"),bg="white",fg="green").place(x=50,y=30)
#Row1
self.var_fname=StringVar()
f_name=Label(frame1,text="First Name",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50,y=100)
self.txt_fname=Entry(frame1,font=("times new roman",15),bg="lightgray",textvariable=self.var_fname)
self.txt_fname.place(x=50,y=130,width=250)
l_name=Label(frame1,text="Last Name",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370,y=100)
self.txt_lname=Entry(frame1,font=("times new roman",15),bg="lightgray")
self.txt_lname.place(x=370,y=130,width=250)
#Row2
contact=Label(frame1,text="Contact No.",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=50,y=170)
self.txt_contact=Entry(frame1,font=("times new roman",15),bg="lightgray")
self.txt_contact.place(x=50,y=200,width=250)
email=Label(frame1,text="Email Address",font=("times new roman",15,"bold"),bg="white",fg="black").place(x=370,y=170)
self.txt_email=Entry(frame1,font=("times new roman",15),bg="lightgray")
self.txt_email.place(x=370,y=200,width=250)
0
That is just half of it though.
0
The main definition problem that gives connect error. def register_data(self):
if self.txt_fname.get()=="" or self.txt_lname.get()=="" or self.txt_contact.get()=="" or self.txt_email.get()=="" or self.cmb_quest.get()=="" or self.txt_answer.get()=="" or self.txt_password.get()=="" or self.txt_cpassword.get()=="":
messagebox.showerror("Error","All fields are required!",parent=self.root)
elif self.txt_password.get()!=self.txt_cpassword.get():
messagebox.showerror("Error","Passwords do not match.")
elif self.var_chk.get()==0:
messagebox.showerror("Error","Please Agree to Our Terms & Conditions")
else:
try:
con=sql.connect(host="localhost",user="root",password="",database="registration_system",cursorclass=sql.cursors.DictCursors)
cur=con.cursor()
cur.execute("select * from registration1 where email=%s",self.txt_email.get())
row=cur.fetchone()
print(row)
if row!=None:
messagebox.showerror("Error","User already exists, please try another username.",parent=self.root)
else:
cur.execute("insert into registration1 (f_name,l_name,contact,email,question,answer,password) values(%s,%s,%s,%s,%s,%s,%s)",
(self.txt_fname.get(),
self.txt_lname.get(),
self.txt_contact.get(),
self.txt_email.get(),
self.cmb_quest.get(),
self.txt_answer.get(),
self.txt_password.get(),
))
con.commit()
con.close()
messagebox.showinfo("Success","Registration successful.",parent=self.root)
self.clear()
except Exception as es:
messagebox.showerror("Err
0
Did I just
0
The main script: def register_data(self):
if self.txt_fname.get()=="" or self.txt_lname.get()=="" or self.txt_contact.get()=="" or self.txt_email.get()=="" or self.cmb_quest.get()=="" or self.txt_answer.get()=="" or self.txt_password.get()=="" or self.txt_cpassword.get()=="":
messagebox.showerror("Error","All fields are required!",parent=self.root)
elif self.txt_password.get()!=self.txt_cpassword.get():
messagebox.showerror("Error","Passwords do not match.")
elif self.var_chk.get()==0:
messagebox.showerror("Error","Please Agree to Our Terms & Conditions")
else:
try:
con=sql.connect(host="localhost",user="root",password="",database="registration_system",cursorclass=sql.cursors.DictCursors)
cur=con.cursor()
cur.execute("select * from registration1 where email=%s",self.txt_email.get())
row=cur.fetchone()
print(row)
if row!=None:
messagebox.showerror("Error","User already exists, please try another username.",parent=self.root)
else:
cur.execute("insert into registration1 (f_name,l_name,contact,email,question,answer,password) values(%s,%s,%s,%s,%s,%s,%s)",
(self.txt_fname.get(),
self.txt_lname.get(),
self.txt_contact.get(),
self.txt_email.get(),
self.cmb_quest.get(),
self.txt_answer.get(),
self.txt_password.get(),
))
con.commit()
con.close()
messagebox.showinfo("Success","Registration successful.",parent=self.root)
self.clear()
except Exception as es:
messagebox.showerror("Error",f"Error due to: {str(es)}",parent
0
I meant the main problem from the whole script.
0
Nevermind, it's all fixed.
0
I had to switch from PyScripter to Visual Studio Code.
0
Teo Ichim is your problem solved..