-1

I'm trying to select a certain row (num) in a table using a SELECT query in mySQL. What am I doing wrong in the query line?

Tried many different syntaxes but most either return False or an EOL error.

@app.route("/users/<num>", methods = ['GET'])
def users_id(num):
    mysql = connectToMySQL('users')
    query = "SELECT * FROM users WHERE id = 'num';"
    users = mysql.query_db(query)
    print(users)
    return render_template('users_show.html', id = num, users = users)

The print statement returns () but I want the whole row

1 Answers1

2

It's probably the query = "SELECT * FROM users WHERE id = 'num';" line. It seems like the query is literally "SELECT * FROM users WHERE id = 'num';", which is not what you want. Can you print query to see if the num input is substituted? I'd guess not. My guess is the existing query is turning up 0 rows because no row has an id of num.

I'd change that line to query = "SELECT * FROM users WHERE id = {};".format(num) so that num is inserted into the string.

Julien Chien
  • 2,052
  • 4
  • 16
  • 32