September 7th, 2013, 04:45 PM
Hi, very new to python and trying to get my Raspberry Pi talking to a MySQL DB via a web form
Can someone shed some light please on why this isn't working?
import MySQLdb as mdb
sensitivity = req.form.getfirst('Sensitivity', '')
threshold = req.form.getfirst('Threshold', '')
con = mdb.connect('localhost', 'root', '', 'mydb')
cur = con.cursor()
cur.execute("UPDATE camvars SET sensitivity = %s",sensitivity)
cur.execute("UPDATE camvars SET threshold = %s",threshold)
Thanks in anticipation
September 7th, 2013, 06:52 PM
Sorted it! Seems python is very sensitive regards indentation.
September 7th, 2013, 11:08 PM
Indentation is how you delimit blocks of code in Python, unlike other languages where you use curly braces or parenthesis or somesuch. So it's not that python is 'sensitive' to indentation, it's that indentation is part of the syntax.
Originally Posted by Chrisla9
For the same reason, if you post code here in the future, it's important to use [code] tags around it to preserve the indentation.