I'm trying to connect database for my login page, using Xampp server (myphpadmin)
The python code as follows:
run.py
from application import app
if __name__=="__main__":
app.run(host ='0.0.0.0', debug=True)
init.py
from flask import Flask
app=Flask(__name__)
from application import main
main.py
from application import app
from flask import Flask,render_template,request
import mysql.connector
@app.route('/')
def login():
return render_template('login.html')
@app.route('/result',methods=['POST','GET'])
def result():
mydb=mysql.connector.connect(
host="localhost",
user="root",
password="",
database="user-system"
)
mycursor=mydb.cursor()
if request.method=='POST':
signup=request.form
username=signup['user']
password=signup['pass']
mycursor.execute("select *form user where name=='"+username+"' and password=='"+password+"'")
r=mycursor.fetchall()
count=mycursor.rowcount
if count==1:
return render_template("test.html")
elif count> 1:
return "More than One USER "
else:
return render_template("login.html")
mydb.commit()
mycursor.close()
The code is running successfully but after login using the database data it redirects me to the following error is :
You're using user
rootwith no password maybe not be allowed. My Suggest is to add new user account with a password to access your MySQL database correctly with this steps:User accountsAdd user accountGlobal Privilegesand click Go