[DB-SIG] warning problem

Andy Dustman andy@dustman.net
18 Aug 2002 13:34:55 -0400

On Fri, 2002-08-16 at 09:39, Watt III, Glenn wrote:
> Ok heres my problem i am running a cgi in which i am updating a database
> here it is

Here's a shorter (untested) version, which may be useful for other
people on this list (or perhaps someone reading the archives before
asking a question, like that'll happen).


import cgi
import sys
import MySQLdb

    query = cgi.FieldStorage()
    print"Please run via CGI... Thank you"

connection = MySQLdb.Connect(host="localhost",user="site",passwd="s1te411",db="backbone")
cursor = connection.cursor()

if query.has_key("accept"):
    header = "Content-type: text/html\n"
    print header
    print """
    print "Well that was kind of useless you didn't even decide whether or not to accept"

columns = 'firstname lastname title email web city state country ' \
          'papertitle abstract cot'.split()
changes = {}

if query['accept'].value == "Yes":
    for c in columns:
        if query.has_key(c):
            changes[c] = query[c].value
    placeholders = [ "%s=%%(%s)s" % (k,k) for k in changes.keys() ]
    stmt = "UPDATE newspapers SET %s" % placeholders
    stmt = 'delete from newpapers where firstname=%s'
    changes['refname'] = query["refname"].value
print stmt % MySQLdb.literal(changes)
cursor.execute(stmt, changes)

Andy Dustman         PGP: 0x930B8AB6
    @       .net     http://dustman.net/andy
"Cogito, ergo sum." -- Rene Descartes
"I yam what I yam and that's all what I yam." -- Popeye