Probleme pour se connecter avec ma base de donnée mysql
maxime_boris
Messages postés
35
Date d'inscription
Statut
Membre
Dernière intervention
-
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
yg_be Messages postés 23541 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour, je voudrais me connecté à ma base de donnée mysql pour créer un formulaire d'inscription malgrés plusieurs tentatives, je n'arrive pas à trouver l'érreur que j'ai pu commettre. La connexion à la base de donnée est nécéssaire pourvalider mon formulaire d'inscription. Quelqu'un pourrait m'éclairer svp ?
Voici mes codes:
from tkinter import * from tkinter import ttk, messagebox import pymysql import os class Formulaire: def __init__(self,root): self.root = root self.root.title("Samaritain") self.root.geometry("1920x1080+0+0") #Champs du formulaire frame1 = Frame(self.root, bg="grey") frame1.place(x=450, y=200, width=700, height=500) title = Label(frame1, text="Créer un compte",font=("algerian",20,"bold"), bg="grey", fg="orange") title.place(x=50,y=50) #Prénom et Nom aff_prenom = Label(frame1, text="Prénom",font=("times new roman",15, "bold"), bg="grey", fg="black").place(x=50, y=100) self.ecri_prenom = Entry(frame1, font=("times new roman",),bg ="lightgrey") self.ecri_prenom.place(x=50, y=130, width=250) aff_nom = Label(frame1, text="Nom", font=("times new roman", 15, "bold"), bg="grey", fg="black").place(x=370, y=100) self.ecri_nom = Entry(frame1, font=("times new roman",), bg="lightgrey") self.ecri_nom.place(x=370, y=130, width=250) #téléphone et email aff_telephone = Label(frame1, text="Téléphone", font=("times new roman", 15, "bold"), bg="grey", fg="black").place(x=50, y=160) self.ecri_telephone = Entry(frame1, font=("times new roman",), bg="lightgrey") self.ecri_telephone.place(x=50, y=190, width=250) aff_email = Label(frame1, text="email", font=("times new roman", 15, "bold"), bg="grey", fg="black").place(x=370, y=160) self.ecri_email = Entry(frame1, font=("times new roman",), bg="lightgrey") self.ecri_email.place(x=370, y=190, width=250) # Question et réponses aff_question = Label(frame1, text="Sélectionner une question", font=("times new roman", 15, "bold"), bg="grey", fg="black").place(x=50, y=220) self.ecri_question = ttk.Combobox(frame1, font=("times new roman",15), state="readonly") self.ecri_question["values"]= ("Select","Ton surnom","Lieu de naissance","Prenom de ta maman", "Film préféré") self.ecri_question.place(x=50, y=250, width=250) self.ecri_question.current(0) aff_repondre = Label(frame1, text="Réponse", font=("times new roman", 15, "bold"), bg="grey", fg="black").place(x=370, y=220) self.ecri_repondre= Entry(frame1, font=("times new roman",), bg="lightgrey") self.ecri_repondre.place(x=370, y=250, width=250) #Password et confirmer le password aff_password = Label(frame1, text="Password", font=("times new roman", 15, "bold"), bg="grey", fg="black").place(x=50, y=280) self.ecri_password = Entry(frame1,show="*",font=("times new roman",), bg="lightgrey") self.ecri_password.place(x=50, y=310, width=250) aff_cfmpassword = Label(frame1, text="Confirme Password", font=("times new roman", 15, "bold"), bg="grey", fg="black").place(x=370, y=280) self.ecri_cfmpassword= Entry(frame1, font=("times new roman",), bg="lightgrey") self.ecri_cfmpassword.place(x=370, y=310, width=250) # les termes et conditions self.var_check= IntVar() chk = Checkbutton(frame1,variable=self.var_check, onvalue=1, offvalue=0, text="J'accepte les conditions et les termes",cursor="hand2", font=("times new roman",12), bg="grey").place(x=50, y=370) # les boutons de validation et connexion btn = Button(frame1, text="Créer", cursor="hand2",command= self.creer,font=("times new roman",15, "bold"), bg='cyan',fg="black").place(x=250, y=430, width=250) btn1 = Button(frame1, text="Connexion", cursor="hand2", font=("times new roman", 15, "bold"), bg='cyan',fg="black").place(x=550, y=50, width=150) def creer(self): if self.ecri_prenom.get()=="" or self.ecri_email.get()=="" or self.ecri_question.get()=="" or self.ecri_repondre.get()=="" or self.ecri_password.get()=="" or self.ecri_cfmpassword.get()=="": messagebox.showerror("Erreur","Remplir les champs",parent=self.root) elif self.ecri_password.get() != self.ecri_cfmpassword.get(): messagebox.showerror("Erreur","Les mots de passes ne sont pas identiques", parent=self.root) elif self.var_check.get()== 0: messagebox.showerror("Erreur", "Veuillez accepter les termes et conditions", parent=self.root) else: try: con = pymysql.connect(host="localhost", user="root", password="", database="creer") cur =con.cursor() cur.execute("select * from compte where email=%s", self.ecri_email.get()) row = cur.fetchone() if row != None: messagebox.showerror("Erreur", "Ce mail existe déja",parent= self.root) else: cur.execute("insert into compte (prenom, nom, telephone, email , question , reponse , password) values(%s,%s,%s,%s,%s,%s,%s)", ( self.ecri_prenom.get(), self.ecri_nom.get(), self.ecri_telephone.get(), self.ecri_email.get(), self.ecri_question.get(), self.ecri_repondre.get(), self.ecri_password.get() )) messagebox.showinfo("Succés", "Votre compte à bien été crée", parent=self.root) con.commit() con.close() except Exception as es: messagebox.showerror("Erreur", f"Erreur de connexion: (str(es))", parent=self.root)
Voici ma base de donnée Mysql:
Windows / Chrome 107.0.0.0
A voir également:
- Probleme pour se connecter avec ma base de donnée mysql
- Se connecter à gmail sur téléphone - Guide
- Se connecter à ma boite hotmail - Guide
- Se connecter a chromecast - Guide
- Base de registre - Guide
- Facebook se connecter à un autre compte - Guide
2 réponses
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
bonjour, ton code ne se comporte pas comme tu le souhaites?