Home > Mobile >  mysql.connector for python : Not all parameters were used in the SQL statement
mysql.connector for python : Not all parameters were used in the SQL statement

Time:07-02

Working on a project, and I'm using MySQL for user database.

I have attempted to fix this issue by changing request.form to request.form.get, but to no avail.

from flask import Flask, render_template, request, redirect, url_for, session
app = Flask(__name__)
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  password="",
  database="jimblonium"
)
mycursor = mydb.cursor()


@app.route('/')
def hello():
    return render_template('index.html')

@app.route("/login")
def login():
    return render_template ('login.html')

@app.route("/l", methods =['GET', 'POST'])
def passIt():
    username = request.form.get("username")
    password = request.form.get("password")
    if request.method == 'POST':
        # return username
        if request.method == 'POST':
            mycursor.execute('SELECT * FROM users WHERE username = % s AND password = % s', (username, password, ))
            account = mycursor.fetchone()
            if account:
                return "done!"

CodePudding user response:

You could try:

myvar =  request.form["username"]
myvartwo = request.form["password"]

CodePudding user response:

You have a syntax error in your query, the placeholders are %s, and you are inserting an space with % s. You need to modify it to:

mycursor.execute('SELECT * FROM users WHERE username = %s AND password = %s', (username, password, ))
  • Related