用表單來提交sql - 1

來源:互聯網
上載者:User
<%
'從表單中提取值
fName = request.form("fName")
lName = request.form("lName")
age = request.form("age")

'建立SQL語句
iStr = "insert into uData (fName, lName, age) "
iStr = iStr & "values ("
iStr = iStr & "'" & fName & "', "
iStr = iStr & "'" & lName & "', "
iStr = iStr & age & ")"

if trim(fName <> "") then
         response.write( iStr & "<BR>")
else
%>

<html>
<body>
<form name=f method=post action="listing1.asp">
Gimme your:<br>
First Name: <input type=text name="fName"><br>
Last Name: <input type=text name="lName"><br>
Age: <input type=text name="age"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

<%
end if
  %>


列表 B:使用 request.form 來輕鬆建立SQL字串。

<%
iStr = "insert into uData "
vStr = "values ("
nStr = "("

' 在表單集合中迴圈,並建立起SQL語句的組成部分
for each x in request.form
         ' 建立欄位名列表
         nStr = nStr & x & ", "
         ' 建立欄位值列表
         if uCase(x) = "AGE" then
                  vStr = vStr & request.form(x) & ", "
         else
                  vStr = vStr & "'" & request.form(x) & "', "
         end if       
next

' 把結尾的", " 從我們建立的字串中去掉
vStr = left(vStr, len(vStr) - 2) & ")"
nStr = left(nStr, len(nStr) - 2) & ") "

' 把SQL語句組裝起來
iStr = iStr & nStr & vStr

if trim(request("fName")) >> "" then
         response.write( iStr & ">BR>")
else
%>

<html>
<body>
<form name=f method=post action="列表2.asp">
Gimme your:<br>
First Name: <input type=text name="fName"><br>
Last Name: <input type=text name="lName"><br>
Age: <input type=text name="age"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

<%
end if
  %>





相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。