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

请问可以教我一下具体的步骤吗?最好有个简单的代码例子,,,

你用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.0;Data 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
%>

 

 

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

追问

先谢谢你!再请教一个问题,就是为什么
我在asp写代码

你的姓名是:

你的密码是:

时出现这个结果?
“你的姓名是”

追答

Request.Form("yourname")这个是表单编辑框名为yourname的数据。
但是ASP不可能出现 你的姓名是 这个结果啊,顶多后面是空的,你检查一下你的页面类型是不是ASP

温馨提示:答案为网友推荐,仅供参考