Jump to content

Taking CGI input and storing it into MYSQL

- - - - -

  • Please log in to reply
1 reply to this topic

#1
r_j

r_j

    Newbie

  • Members
  • Pip
  • 4 posts
Hi guys, i have a basic form that takes first name and last name, via html/python, but im having trouble storing it into mysql database



#!/usr/bin/env python

print "Content-type: text/html"

print


import cgi



def main():

    

    form = cgi.FieldStorage()

    

    if form.has_key("firstname"):

            print "<h1>Hello", form["firstname"].value,",",form["lastname"].value, "</h1>"

    else:

            print "<h1>Error! Please enter first name.</h1>"



now my problem is i dont know how to add this to my simple mysql database, I know how to open the connection, cursors, and send commands via python but my problem is incorporating the value that i have got from the html input and sending it to mysql...

sql = """INSERT INTO EMPLOYEE(FIRST_NAME,

          LAST_NAME)

         VALUES (************)"""


would i put the form.["firstname"].value in the VALUES section...or do i have to do something else...

#2
r_j

r_j

    Newbie

  • Members
  • Pip
  • 4 posts
got it to work, just used this


cursor.execute("INSERT INTO table VALUES (%s, %s, %s)", (var1, var2, var3)) 






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users