I am currently having a problem with my code. I know that there are many answers to this question on the website, but I tried everything, and I didn't manage to solve the problem.
I am using flask, if that helps.
Here is my code :
conn = sqlite3.connect(db)
cur = conn.cursor()
IdClub=determiner_id_club(nom_club)
sql= "SELECT idClub FROM Inscription WHERE idClub=? AND idAdherent=?"
#Vérifier si l'utilisateur est inscrit dans le club
params=(IdClub,idAdherent)
print(params)
cur.execute(sql,params)
verif_club = cur.fetchone()
return (verif_club)
@app.route('/create')
def create():
msg_affiche = ""
idAdherent=flask.session["idAdherent"]
nom_club= request.args.get("nom_club")
date = request.args.get("date")
heure = request.args.get("heure")
description = request.args.get("description")
if verif_club(nom_club,idAdherent) is None :
print(verif_club(nom_club,idAdherent))
#Si le booléen est Faux
msg_affiche = "vous n'êtes pas inscrit à ce club"
return render_template("create_event.html", msg = msg_affiche)
else:
conn = sqlite3.connect(db)
cur = conn.cursor()
sql2="INSERT INTO Evenements ('Date','Heure','Description') VALUES (?,?,?,?)"
cur.execute(sql2,[date,heure,description])
sql3="INSERT INTO Organisation idClub=?" #lier cet évenement à un club
cur.execute(sql2,determiner_id_club(nom_club))
conn.commit()
cur.close()
conn.close()
msg_affiche="Félicitations ! Vous avez créer un évenement"
return render_template("create_event.html",msg=msg_affiche) ```
CodePudding user response:
I have also tried this :
def verif_club(nom_club,idAdherent):
conn = sqlite3.connect(db)
cur = conn.cursor()
IdClub=determiner_id_club(nom_club)
sql= "SELECT idClub FROM Inscription WHERE idClub=? AND idAdherent=?"
#Vérifier si l'utilisateur est inscrit dans le club
cur.execute(sql,[IdClub,idAdherent])
res=cur.fetchone()
return (res)
CodePudding user response:
Here is the code of the fonction
def determiner_id_club(nom_club):
conn = sqlite3.connect(db)
cur = conn.cursor()
sql1="SELECT idClub FROM Clubs WHERE NomClub=?"
idClub=cur.execute(sql1,(nom_club,))
return idClub