Skip to content

Instantly share code, notes, and snippets.

@davepape
Created April 2, 2014 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepape/9936522 to your computer and use it in GitHub Desktop.
Save davepape/9936522 to your computer and use it in GitHub Desktop.
# Perform an 'update' query on the sample database, with data input by the user
import MySQLdb
db = MySQLdb.connect(host='localhost', port=3306, user='myusername', passwd='mypassword', db='world')
cur = db.cursor()
print 'enter new name for City 1:'
newname = raw_input()
# Include the data in the query; *NOTE* that this does not do any safety checks / escaping of the data - it's an easy target for an SQL injection attack
query = "update City set Name='" + newname + "' where id=1"
print query
cur.execute(query)
cur.close()
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment