Queries with python and html
I am new to scripting. I am using python and html to create a web interface to update and query mysql on CentOS 6.6. I am using MySQL version 14.14, distibution 5.1.73, python version 2.6.6, apache version 2.2.15.
Here is the python script I have so far and it does not work, error states that not all arguments converted during string formatting:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# enable debugging
import cgitb
cgitb.enable()
import cgi
import MySQLdb as mdb
db = "postfix"
host = "localhost"
port = 3306
dbuser = "dbuser"
dbpass = "dbpassword"
## Entrys from SearchRelay.py
form = cgi.FieldStorage()
DevHost = form.getvalue('DevHost') #This variable is pulled from a previous web page that takes user input
## Verification Page
print "Content-type: text/html"
print
print """
<html>
<head>
<title>Search for a Device</title>
</head>
<body style="background-color:lightgrey">
<h3>Here is your device(s):</h3>
<hr>
"""
## Searching the database
con = mdb.connect(host, dbuser, dbpass, db)
with con:
cur = con.cursor()
query = ("SELECT ip_address, hostname, allowed_external, iser, approver, note, added FROM clients WHERE hostname LIKE %s OR ip_address LIKE %s")
cur.execute(query, (DevHost, DevHost))
data = "%s,%s,%s,%s,%s,%s,%s"
for (ip_address, hostname, allowed_external, iser, approver, note, added) in cur:
print("IP: " % data[0], "Hostname: " % data[1], "External: " % data[2], "ISER: " % data[3], \
"Approver: " % data[4], "Note: " % data[5], "Added On: " % data[6])
cur.close()