怎么用asp代码把html表单数据提交到access数据库中?

怎么用asp代码把html表单数据提交到access数据库中?,第1张

你用HTML提交的话分两个页面:

001.html(表单);

002.asp(写入数据,写成返回表单页)。

----------------------------------------------------

001.html 表单:

-------------------------------------------------------------------------------------------------------------

<form name="" action="002.asp" method="POST" >

名称:<input name="name" type="text" style="width:250px"  maxlength="200"><br>

等级:<input name="level" type="text" style="width:250px"  maxlength="200"><br>

<input name="submit1222" type="submit" value="提交">

</form>

----------------------------------------------------

002.asp 内容:

--------------------------------------------------------------------------------------------------------------

<%

Set conn = Server.CreateObject("ADODB.Connection")

DBPath = Server.MapPath("data.mdb")'数据库位置比如相同目录下的data.mdb

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &DBPath

Set rs = Server.CreateObject("ADODB.Recordset")

sql="select * from abc "  '数据库表名是abc.(表里通常第一列为ID,为自动编号,我加了两列name和level)

rs.open sql,conn,1,3

        rs.addnew

  rs("name")=Request.Form("name")

  rs("level")=Request.Form("level")

  rs.update

  response.Write "<script language='JavaScript'>{window.alert( '添加到数据库完成!')window.location.href= '001.html'}</script>"

        response.end

rs.close

set rs=nothing

%>

看来我太闲了~都写出来了,干脆加个数据库传给你好了。

正常要写三步,

第一步是 后端接收数据。

第二步是 传递数据到业务逻辑处理。

第三步是 业务逻辑处理数据后传递到数据访问层 *** 作到数据库。

不过也有简化的。在接收数据时直接 *** 作数据库的也有,不过不安全。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9944781.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-03
下一篇2023-05-03

发表评论

登录后才能评论

评论列表(0条)

    保存