I have a html login form.which collects a users username and password . I also have a script which collects them and stores it . I was wondering if it was possible to check if the username and password already exists in the MySQL database before storing in the database.
Html form:
<!DOCTYPE html>
<html>
<head>
<title>login</title>
</head>
<body>
<form action="login.py" method="GET">
First name:<br>
<input type="text" name="user_name"><br>
Last name:<br>
<input type="text" name="password"><br>
</form>
</body>
</html>
Login script
import cgitb
cgitb.enable()
import cgi
form = cgi.FieldStorage()
user_name = form["user_name"].value
password = form["password"].value
import pymysql
conn = pymysql.connect(db='userdb',
user='root', passwd='12346',
host='localhost')
cursor = conn.cursor()
query= "INSERT INTO users VALUES
('{user_name}',{password})"
cursor.execute(query.format(user_name=user-
name, password=password))
conn.commit()
Is it possible to check if the username and password from the html form has a match in the database?