-
Notifications
You must be signed in to change notification settings - Fork 0
/
t3.py
43 lines (33 loc) · 844 Bytes
/
t3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!C:\Python27\python.exe -u
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import sys, os
import MySQLdb as mdb
con = None
print "Content-type: text/html"
print
print """
<html>
<body>
"""
form = cgi.FieldStorage()
t = form.getvalue("t", "0")
h = form.getvalue("h", "0")
p = form.getvalue("p", "0")
con = mdb.connect('localhost', 'user', 'password', 'temperature');
qry = "INSERT INTO weather (temp,humidity,pressure) VALUES('" + t + "','" + h + "','" + p + "')"
print qry
with con:
cur = con.cursor()
cur.execute(qry)
con.close()
print """
<form method="get" action="t2.py">
<p>temperature: <input type="text" name="temperature"/></p>
<p>humidity: <input type="text" name="humidity"/></p>
<p>pressure: <input type="text" name="pressure"/></p>
</form>
</body>
</html>
"""