I can't seem to find out what I'm doing wrong. It would be great to receive some feedback!
import cgi, cgitb, MySQLdb
cgitb.enable()
db = MySQLdb.connect(db="watchdog",user="root",passwd="XXXXXXX")
c = db.cursor()
print ("Content-type:text/html\n")
print ("<html><head><title>WatchdogServer</title></head><body>")
data = cgi.FieldStorage()
hostname = data.getvalue("hostname")
osName = data.getvalue("osName")
ramUsage = data.getvalue("ramUsage")
cpuUsage = data.getvalue("cpuUsage")
diskUsage = data.getvalue("diskUsage")
c.execute("""CREATE TABLE IF NOT EXISTS `{}` (`ID` int(11) NOT NULL,`hostname` text NOT NULL,`osName` text NOT NULL,`ramUsage` text NOT NULL,`cpuUsage` text NOT NULL,`diskUsage` text NOT NULL,`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=latin1; """.format(hostname))
c.execute("""INSERT INTO `{}` (`hostname`, `osName`, `ramUsage`, `cpuUsage`, `diskUsage`) VALUES (`{}`,`{}`,`{}`,`{}`,`{}`);""".format(hostname,hostname,osName,ramUsage,cpuUsage,diskUsage))
print ("</body></html>")
For some reason it is looking for a column with the hostname variable. But even if I change all the column names and try again I still receive the same error everytime. :(
_mysql_exceptions.OperationalError: (1054, "Unknown column 'BOB-PC' in 'field list'")
Hope anyone of you can assist me!
Cheers! Bob