想要一个ASP表单提交 写入mdb数据库的例子!
我创建了一个表单,要求填写姓名,地址,e-mail并把值写入对应数据库name,add,e-mail里面,请问代码应该怎么写??...
我创建了一个表单,要求填写 姓名,地址,e-mail 并把值写入对应数据库 name, add, e-mail里面,请问代码应该怎么写??
展开
1个回答
展开全部
<form name="form1" method="post" action="">
<p>
姓名<input type="text" name="name">
</p>
<p>
地址<input type="text" name="address">
</p>
<p>
e-mail<input type="text" name="email">
</p>
<p>
<input type="submit" name="Submit" value="提交">
</p>
</form>
<%
if request("submit")="提交" then
if request.form("name")=""or request.form("address")=""or request.form("email")="" then
response.Write"<script>alert('资料填写不完整,请重新输入!');history.back();</script>"
response.end
else
set conn=server.createobject("adodb.connection")conn.open "driver={microsoft access driver(*.mdb)};dbq="&server.mappath("数据库.mdb")
name=request.form("name")
address=request.form("address")
email=request.form("email")
exec="insert into 表(name,address,email)values('"+name+"','"+address+"','"+email+"')"
conn.execute exec
conn.close
set conn=nothing
response.Write"<script>alert('信息添加成功');history.back();</script>"'history.back();表示刷新
response.end
end if
end if
%>
<p>
姓名<input type="text" name="name">
</p>
<p>
地址<input type="text" name="address">
</p>
<p>
e-mail<input type="text" name="email">
</p>
<p>
<input type="submit" name="Submit" value="提交">
</p>
</form>
<%
if request("submit")="提交" then
if request.form("name")=""or request.form("address")=""or request.form("email")="" then
response.Write"<script>alert('资料填写不完整,请重新输入!');history.back();</script>"
response.end
else
set conn=server.createobject("adodb.connection")conn.open "driver={microsoft access driver(*.mdb)};dbq="&server.mappath("数据库.mdb")
name=request.form("name")
address=request.form("address")
email=request.form("email")
exec="insert into 表(name,address,email)values('"+name+"','"+address+"','"+email+"')"
conn.execute exec
conn.close
set conn=nothing
response.Write"<script>alert('信息添加成功');history.back();</script>"'history.back();表示刷新
response.end
end if
end if
%>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询