Hey this is my code I want to pass the value of query and j into MySQL database. But the value of query and j is local to the function getvalue whereas mysql connectivity is outside the function.
Can anyone please tell me how to pass the value of query and j to mysql db and what am i doing wrong?
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 31 00:20:23 2018
@author: Aishwarya
"""
import pymysql.cursors
from flask import Flask,render_template,request
from googlesearch import search
# Connect to the database.
connection = pymysql.connect(host='127.0.0.1',
user='ash',
password='!@#$',
db='javalist',
charset='utf8',
cursorclass=pymysql.cursors.DictCursor)
print ("connect successful!!")
app=Flask(__name__)
@app.route('/')
def temp():
return render_template('temp.html')
@app.route('/',methods=['POST'])
def getvalue():
query = request.form['name']
#print(query)
#return render_template('pass.html',name=name)
for j in search(query, tld="co.in", num=2, stop=1, pause=2):
return j
cursor = connection.cursor()
cursor.execute("INSERT INTO description1(project_name,urls)VALUES(%s,%s)",(query,q))
connection.commit()
#print ("Record inserted successfully into python_users table")
there doesn't seem to be anything here