Feb-02-2019, 01:57 PM
name = request.args.get('name') month = request.args.get('month') year = request.args.get('year') try: if '=' not in name + month + year: cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, month, year) ) elif '=' not in name + year: cur.execute( '''SELECT * FROM jobs WHERE clientID = (SELECT id FROM clients WHERE name = %s) and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (name, year) ) elif '=' not in month + year: cur.execute( '''SELECT * FROM jobs WHERE MONTH(lastvisit) = %s and YEAR(lastvisit) = %s ORDER BY lastvisit DESC''', (month, year) ) elif '=' not in year: cur.execute( '''SELECT * FROM jobs WHERE YEAR(lastvisit) = %s ORDER BY lastvisit ASC''', year ) else:Hello, iam tryting to execute mysql queries based on python variables.
Problem is that only the first clause works as expected and not the rest.'=' means variables contains no value.
How can i make it work?
Request arguments come from a previous endpoint being executed that had a form within it to get the values. elif '=' not in month + year: and elif '=' not in month + year: and elif '=' not in name + year: does no return any results althoughtthey are present innto the database.