-
Notifications
You must be signed in to change notification settings - Fork 0
/
stest.py
executable file
·71 lines (57 loc) · 1.67 KB
/
stest.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""Python, MySQL and CGI (Common Gateway Interface) all
in the same demo script.
Note - need to moderate live public boards of this type!
"""
import cgi
import MySQLdb
# Following line is what you would need to create table
# prior to running for the first time
#
# create table comment
# (info text, enteredat timestamp,
# cid int primary key not null auto_increment)
# Connect to MySQL database
db = MySQLdb.connection(host="localhost",user="root",passwd="Tulsi@991",db="searchdb")
# Collect values from form
inputs = cgi.FieldStorage()
fill = {}
for key in inputs:
fill[key] = inputs[key].value
# If the form was completed, save what was entered on it
"""try:
said = fill["info"]
form = 1
db.query('insert into comment (info) values ("' \
+said.replace('"',r'\"') \
+'")')
except:
form = 0
"""
# Read back 10 latest comments
db.query("SELECT * FROM test WHERE(STOVEPIPE or DATACENTER or VSN or FQDN or IP or PORT or POLICY or DEVICE LIKE ?")
r = db.store_result()
history = ""
for row in r.fetch_row(10):
history += cgi.escape(row[0]) + "<br>\n"
# Generate the HTML response
#######################################################
print """content-type: text/html
<html>
<head>
<title>MySQL and Python on the Web</title>
</head>
<body bgcolor=#FFCCFF>
<h1>Message Board Report</h1>
This is a message board report demo.<br>
<b>This is what has been going on ... </b><br>
"""
print history
print """
<form method=POST>Please enter your comment: <input name=info><br>
<input type=submit>
</form>
Demonstration from Well House Consultants.<br>
<a href=http://www.wellho.net/>Website</a>
</body></html>
"""