Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import cgi,cgitb
- import pymysql.cursors
- #
- # Getting values from signup page fields
- #
- # Create instance of FieldStorage
- form = cgi.FieldStorage()
- # Get data from fields
- username = form.getvalue('username')
- password = form.getvalue('password')
- email = form.getvalue('email')
- #
- # Create connection config for DataBase
- #
- connection=pymysql.connect(
- host='localhost',
- user='test',
- password='password',
- db='test',
- cursorclass=pymysql.cursors.DictCursor)
- #INSERT new user entries
- #
- try:
- with connection.cursor() as cursor:
- insert_query="INSERT INTO users (user_name,user_pass,user_email) VALUES (%s,%s,%s);"
- cursor.execute(insert_query,(username,password,email))
- # For saving changes in DB
- connection.commit()
- finally:
- connection.close()
- #showing variable values in browser for confirmation that it's taking values from field and it will be
- # submitted to DB also
- print("Content-type:text/html")
- print()
- print("Content-type:text/html\r\n\r\n")
- print("<html>")
- print("<head>")
- print("<title> Adding Credentials ... </title>")
- print("</head>")
- print ("<body>")
- print ("<h2>Hello %s and your email is %s and pass is %s</h2>" % (username,email,password))
- print ("</body>")
- print ("</html>")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement