Revised: [DB-SIG] MySQLdb +cgi

Paul DuBois paul@dubois.ws
Tue, 30 Oct 2001 15:04:17 -0600


At 12:22 PM -0700 10/30/01, Jackson wrote:
>Ok --
>Here's the corrected script. The host variable prints out fine,
>but it's still no updating db (Yep, I verified the username and 
>password") What about the construction of the exicute statement?
>Do we need placeholders(?) or (%s)?
>
>Thanks,
>David
>
>--------------------------- Script ---------------
>#!/usr/bin/python
>import cgi, MySQLdb
>print "Content-Type: text/html\n"
>
>form = cgi.FieldStorage()
>if form.has_key("node"):
>	host=form["node"].value
>	print "<p>"
>	print "Hostname: ",host
>	print "</p>"
>	db =SQLdb.connect("localhost","rca","rca1234","sirinfo")
>	rca = db.cursor()
>	rca.execute(""" insert into test(node)values(?)""",host)


? isn't the placeholder for MySQLdb.  Try:

rca.execute(""" insert into test(node)values(%s)""",(host,))

>
>
>else:
>	print "<h1>Dis doesn't look right</h1>"

--