简体   繁体   中英

Bring in a variable into a SQL statement with CGI Python

All I want to do is do an update statement and bring in two cgi python variables: inputMin, and inputMax.

Here's what I have:

curInsert.execute("Update User set SetMinF = %d, SetMaxF = %d" .format(inputMin, inputMax))    

What's the proper syntax to bring in a variable? %d ? %s ? ? ?

尝试curInsert.execute("Update User set SetMinF = %s, SetMaxF = %s" % (inputMin, inputMax))

I figured it out, it was something dumb. I was using floats and needed %f, so it looks like this:

curInsert.execute("Update User set SetMinF = %f, SetMaxF = %f" % (inputMin, inputMax)) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM