search.py
import cgi
import yate
import sqlite3
import sys
import os
print(yate.start_response())
connection = sqlite3.connect('users.sqlite')
cursor = connection.cursor()
form=cgi.FieldStorage(keep_blank_values=True)
table=form['tables'].value
bincard=form['bincard'].value
cursor.execute("SELECT * FROM (?) where BinCard=?",(table,bincard))
pt = from_db_cursor(cursor)
pt.format = True
print(pt.get_html_string())
search.html:
<html>
<head>
<title>Stock Entry</title>
<link type="text/css" rel="stylesheet" href="coach.css" />
</head>
<body>
<img src="images/logo-cel-transparent_0.png" width="74" height="64">
<strong>
<img src="images/logo-cel-transparent_0.png" alt="Cel logo" width="74" height="64" align="right">
</strong>
<h1 align="center">
<strong>Central Electronics Limited</strong>
</h1>
<p> </p>
<h2 align="center">Storage Management System</h2>
<p> </p>
<p align="center">SEARCH!!</p>
<p align="center"> </p>
<form action="cgi-bin/search.py">
<div align="center">
<strong>Table :</strong>
<select name="tables">
<option value="OPB">OPB</option>
<option value="TRAN">TRAN</option>
</select>
<strong>BinCard :</strong>
<input type="text" name="bincard">
<br>
<br>
<input type="submit" value="Submit">
</div>
</form>
</body>
错误:
127.0.0.1 - - [28/Jun/2015 16:29:10] "GET /cgi-bin/search.py?tables=TRAN&bincard
=123 HTTP/1.1" 200 -
127.0.0.1 - - [28/Jun/2015 16:29:10] command: C:\Python34\python.exe -u C:\Pytho
n34\ProjectShivam\webapp\cgi-bin\search.py
127.0.0.1 - - [28/Jun/2015 16:29:10] b'Traceback (most recent call last):\r\n F
ile "C:\\Python34\\ProjectShivam\\webapp\\cgi-bin\\search.py", line 14, in <modu
le>\r\n cursor.execute("SELECT * FROM (?) where BinCard==?",(table,bincard))\
r\nsqlite3.OperationalError: near "?": syntax error\r\n'
我正在尝试从两个表中的任何一个表中检索数据,具体取决于用户在search.html中选择的内容。但如果无法弄清楚要写的查询,因为我不知道事先选择了哪个表。帮助