如何把表单内容提交到数据库
打个比方,我要做个记录,要登记姓名、年龄、性别,然后制作了一个提交表单,但怎么把姓名、年龄、性别这些内容提交到数据库?请告诉我在提交表单里要加什么程序?我不需要网络,直接...
打个比方,我要做个记录,要登记姓名、年龄、性别,然后制作了一个提交表单,但怎么把姓名、年龄、性别这些内容提交到数据库?
请告诉我在提交表单里要加什么程序?
我不需要网络,直接在本地提交,然后提交到本地数据库。
数据库就用ACCESS。
能不能提供一个参照程序?我只要改改字段就行了 展开
请告诉我在提交表单里要加什么程序?
我不需要网络,直接在本地提交,然后提交到本地数据库。
数据库就用ACCESS。
能不能提供一个参照程序?我只要改改字段就行了 展开
4个回答
展开全部
conn.asp我用的SQL数据库数据源连接,你改下连接方式就是了
=================================================================
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
rTitle=request.Form("title")
rName=request.Form("name")
rQq=request.Form("qq")
rTx=request.Form("tx")
rContent=request.Form("content")
rSubmit=request.Form("Submit")
Dim MyDateTime
MyDateTime=FormatDateTime(Date,1)
if rSubmit="" then
response.Write("<Script language=javascript>alert('留言失败!');this.location.href='message.asp';</Script>")
else
'Set Conn=Server.CreateObject("ADODB.Connection")
'Conn.ConnectionString="driver={SQL Server};server=127.0.0.1;uid=ms;pwd=123;Database=AS_message"
Set conn=Server.CreateObject("ADODB.Connection")
'Conn.open
'conn.ConnectionString="driver={SQL Server};server=127.0.0.1;uid=ms;pwd=123;database=AS_message"
conn.open"DSN=aspdbs;UID=sm;PWD=123;Database=AS_message"
'if conn.State=1 then
'Response.Write("数据库成功打开")
'end if
conn.execute("insert into message(ms_title,ms_name,ms_qq,ms_toux,ms_content,ms_time) values ('"+rTitle+"','"+rName+"','"+rQq+"','"+rTx+"','"+rContent+"','"+MyDateTime+"')")
response.Write("<Script language=javascript>alert('留言成功!');this.location.href='message.asp';</Script>")
end if
%>
</body>
</html>
====================================================================
message.asp 这个页面有表单提交数据,还有显示分页数据功能,只能参考因没无法穿数据库给你
自己研究吧
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASP流言板</title>
<style type="text/css">
<!--
.dhk {
background-image: url(dhk.gif);
height: 145px;
background-repeat: repeat;
text-align: center;
width: 510px;
}
.style5 {
font-family: "汉鼎繁随意";
color: #003366;
font-size: 36px;
font-weight: bold;
}
.style6 {
color: #330066;
font-size: 12px;
}
.bg {
background-image: url(bg0.gif);
background-repeat: no-repeat;
height: 145px;
width: 510px;
background-position: center center;
border: 1px dashed #FF6633;
}
.tijiao {
font-family: "汉鼎繁随意";
font-size: 12px;
font-weight: normal;
height: 20px;
width: 50px;
border: 1px dashed #FF6633;
}
.style7 {color: #FF3333}
.text {
border: 1px dashed #FF6633;
}
.style8 {font-family: "汉鼎繁随意"}
.style9 {
color: #660099;
font-family: "汉鼎繁随意";
font-size: 18px;
}
-->
</style>
</head>
<body>
<%
Set conn=Server.CreateObject("ADODB.Connection")
'conn.ConnectionString="driver={SQL Server};server=127.0.0.1;uid=ms;pwd=123;database=AS_message"
conn.open"DSN=aspdbs;UID=sm;PWD=123;Database=AS_message"
Set rs=Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection=conn
rs.CursorType=3
rs.open"select * from message"
rs.pagesize=3
page=Clng(Request.QueryString("page"))
if page<1 then
page=1
end if
if page>rs.pagecount then
page=rs.pagecount
end if
rs.AbsolutePage=page
%>
<Script language="JavaScript">
function ClickOn(){
if(document.myform.title.value==""){
window.alert("请输入标题!");
return false;
}
if(document.myform.name.value==""){
window.alert("请输入昵称!");
return false;
}
if(document.myform.qq.value==""){
window.alert("请输入您的QQ!");
return false;
}
if(document.myform.content.value==""){
window.alert("请输入您要留言的内容!");
return false;
}
if(document.myform.content.value.length>250){
window.alert("您的留言的内容太长,请务大于250个字符!");
return false;
}
return true;
}
</Script>
<table width="642" border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#666666" bordercolordark="#CCCCCC" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><div align="center" class="style5">ASP留言板</div></td>
</tr>
<%for i=1 to rs.pagesize
'varNO=(page-1)*rs.pagesize+i
'do while rs.eof=false
%>
<tr>
<td width="126" height="33"><div align="right" class="style6">标 题:</div></td>
<td width="510" class="style6"><div align="left">
<span class="style9">
<%response.Write(rs("ms_title"))%>
</span> </div></td>
</tr>
<tr>
<td><table width="72%" height="136" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="105" colspan="2"><div align="center"><img src="<%response.Write(rs("ms_toux"))%>" width="120" height="113"></div></td>
</tr>
<tr class="style6">
<td width="30%" height="15"><div align="left">昵称:</div></td>
<td width="70%" class="style7"><%response.Write(rs("ms_name"))%> </td>
</tr>
<tr class="style6">
<td height="15"><div align="left">OICQ:</div></td>
<td class="style7"><%response.Write(rs("ms_qq"))%> </td>
</tr>
</table>
<div align="center"></div></td>
<td align="center" class="dhk"><table width="496" height="134" border="0" cellspacing="0">
<tr class="style6">
<td width="40" height="14"> </td>
<td width="435"> </td>
<td width="15"> </td>
</tr>
<tr class="style6">
<td height="102"> </td>
<td align="left" valign="top"><span class="style7">
<%response.Write(rs("ms_content"))%>
</span></td>
<td> </td>
</tr>
<tr class="style6">
<td height="17"> </td>
<td><div align="right" class="style8"><%response.Write(rs("ms_time"))%></div></td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<%
rs.movenext
'loop
if rs.eof then exit for
next
%>
</table>
<br>
<table width="642" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="style6"><div align="right">
<%
if page=1 then
Response.Write("首"&" "&" "&"页"&" "&" ")
else Response.Write("<a href=message.asp?page=1>首"&" "&" "&"页</a>"&" "&" ")
end if
if page=1 then
Response.Write("上一页"&" "&" ")
else Response.Write("<a href=message.asp?page="&page-1&">上一页</a>"&" "&" ")
end if
if page=rs.pagecount then
Response.Write("下一页"&" "&" ")
else Response.Write("<a href=message.asp?page="&page+1&">下一页</a>"&" "&" ")
end if
if page=rs.pagecount then
Response.Write("最后一页")
else Response.Write("<a href=message.asp?page="&rs.pagecount&">最后一页</a>")
end if
%>
</div></td>
</tr>
</table>
<form name="myform" method="post" action="conn.asp" onSubmit="return ClickOn()">
<table width="642" border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#666666" bordercolordark="#CCCCCC" bgcolor="#FFFFFF">
<tr>
<td width="126" class="style6"><div align="right">标 题:</div></td>
<td width="510"><input name="title" type="text" class="text" id="title"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">昵 称:</div></td>
<td><input name="name" type="text" class="text" id="name"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">O I C Q:</div></td>
<td><input name="qq" type="text" class="text" id="qq"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">头 像:</div></td>
<td><img src="txr.jpg" width="120" height="113"> <img src="txy.gif" width="120" height="113"> <img src="txs.jpg" width="120" height="113"> <img src="txsi.jpg" width="120" height="113"><br>
<input name="tx" type="radio" value="txr.jpg" checked>
<input type="radio" name="tx" value="txy.gif">
<input type="radio" name="tx" value="txs.jpg">
<input type="radio" name="tx" value="txsi.jpg"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">内 容:</div></td>
<td><textarea name="content" class="bg" id="content"></textarea></td>
</tr>
<tr>
<td colspan="2" class="style6">
<div align="center">
<input name="Submit" type="submit" class="tijiao" value="提交">
<input name="Submit" type="reset" class="tijiao" value="取消">
</div>
<div align="right"> </div></td>
</tr>
</table>
</form>
</body>
</html>
=================================================================
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
rTitle=request.Form("title")
rName=request.Form("name")
rQq=request.Form("qq")
rTx=request.Form("tx")
rContent=request.Form("content")
rSubmit=request.Form("Submit")
Dim MyDateTime
MyDateTime=FormatDateTime(Date,1)
if rSubmit="" then
response.Write("<Script language=javascript>alert('留言失败!');this.location.href='message.asp';</Script>")
else
'Set Conn=Server.CreateObject("ADODB.Connection")
'Conn.ConnectionString="driver={SQL Server};server=127.0.0.1;uid=ms;pwd=123;Database=AS_message"
Set conn=Server.CreateObject("ADODB.Connection")
'Conn.open
'conn.ConnectionString="driver={SQL Server};server=127.0.0.1;uid=ms;pwd=123;database=AS_message"
conn.open"DSN=aspdbs;UID=sm;PWD=123;Database=AS_message"
'if conn.State=1 then
'Response.Write("数据库成功打开")
'end if
conn.execute("insert into message(ms_title,ms_name,ms_qq,ms_toux,ms_content,ms_time) values ('"+rTitle+"','"+rName+"','"+rQq+"','"+rTx+"','"+rContent+"','"+MyDateTime+"')")
response.Write("<Script language=javascript>alert('留言成功!');this.location.href='message.asp';</Script>")
end if
%>
</body>
</html>
====================================================================
message.asp 这个页面有表单提交数据,还有显示分页数据功能,只能参考因没无法穿数据库给你
自己研究吧
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ASP流言板</title>
<style type="text/css">
<!--
.dhk {
background-image: url(dhk.gif);
height: 145px;
background-repeat: repeat;
text-align: center;
width: 510px;
}
.style5 {
font-family: "汉鼎繁随意";
color: #003366;
font-size: 36px;
font-weight: bold;
}
.style6 {
color: #330066;
font-size: 12px;
}
.bg {
background-image: url(bg0.gif);
background-repeat: no-repeat;
height: 145px;
width: 510px;
background-position: center center;
border: 1px dashed #FF6633;
}
.tijiao {
font-family: "汉鼎繁随意";
font-size: 12px;
font-weight: normal;
height: 20px;
width: 50px;
border: 1px dashed #FF6633;
}
.style7 {color: #FF3333}
.text {
border: 1px dashed #FF6633;
}
.style8 {font-family: "汉鼎繁随意"}
.style9 {
color: #660099;
font-family: "汉鼎繁随意";
font-size: 18px;
}
-->
</style>
</head>
<body>
<%
Set conn=Server.CreateObject("ADODB.Connection")
'conn.ConnectionString="driver={SQL Server};server=127.0.0.1;uid=ms;pwd=123;database=AS_message"
conn.open"DSN=aspdbs;UID=sm;PWD=123;Database=AS_message"
Set rs=Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection=conn
rs.CursorType=3
rs.open"select * from message"
rs.pagesize=3
page=Clng(Request.QueryString("page"))
if page<1 then
page=1
end if
if page>rs.pagecount then
page=rs.pagecount
end if
rs.AbsolutePage=page
%>
<Script language="JavaScript">
function ClickOn(){
if(document.myform.title.value==""){
window.alert("请输入标题!");
return false;
}
if(document.myform.name.value==""){
window.alert("请输入昵称!");
return false;
}
if(document.myform.qq.value==""){
window.alert("请输入您的QQ!");
return false;
}
if(document.myform.content.value==""){
window.alert("请输入您要留言的内容!");
return false;
}
if(document.myform.content.value.length>250){
window.alert("您的留言的内容太长,请务大于250个字符!");
return false;
}
return true;
}
</Script>
<table width="642" border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#666666" bordercolordark="#CCCCCC" bgcolor="#FFFFFF">
<tr>
<td colspan="2"><div align="center" class="style5">ASP留言板</div></td>
</tr>
<%for i=1 to rs.pagesize
'varNO=(page-1)*rs.pagesize+i
'do while rs.eof=false
%>
<tr>
<td width="126" height="33"><div align="right" class="style6">标 题:</div></td>
<td width="510" class="style6"><div align="left">
<span class="style9">
<%response.Write(rs("ms_title"))%>
</span> </div></td>
</tr>
<tr>
<td><table width="72%" height="136" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="105" colspan="2"><div align="center"><img src="<%response.Write(rs("ms_toux"))%>" width="120" height="113"></div></td>
</tr>
<tr class="style6">
<td width="30%" height="15"><div align="left">昵称:</div></td>
<td width="70%" class="style7"><%response.Write(rs("ms_name"))%> </td>
</tr>
<tr class="style6">
<td height="15"><div align="left">OICQ:</div></td>
<td class="style7"><%response.Write(rs("ms_qq"))%> </td>
</tr>
</table>
<div align="center"></div></td>
<td align="center" class="dhk"><table width="496" height="134" border="0" cellspacing="0">
<tr class="style6">
<td width="40" height="14"> </td>
<td width="435"> </td>
<td width="15"> </td>
</tr>
<tr class="style6">
<td height="102"> </td>
<td align="left" valign="top"><span class="style7">
<%response.Write(rs("ms_content"))%>
</span></td>
<td> </td>
</tr>
<tr class="style6">
<td height="17"> </td>
<td><div align="right" class="style8"><%response.Write(rs("ms_time"))%></div></td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<%
rs.movenext
'loop
if rs.eof then exit for
next
%>
</table>
<br>
<table width="642" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="style6"><div align="right">
<%
if page=1 then
Response.Write("首"&" "&" "&"页"&" "&" ")
else Response.Write("<a href=message.asp?page=1>首"&" "&" "&"页</a>"&" "&" ")
end if
if page=1 then
Response.Write("上一页"&" "&" ")
else Response.Write("<a href=message.asp?page="&page-1&">上一页</a>"&" "&" ")
end if
if page=rs.pagecount then
Response.Write("下一页"&" "&" ")
else Response.Write("<a href=message.asp?page="&page+1&">下一页</a>"&" "&" ")
end if
if page=rs.pagecount then
Response.Write("最后一页")
else Response.Write("<a href=message.asp?page="&rs.pagecount&">最后一页</a>")
end if
%>
</div></td>
</tr>
</table>
<form name="myform" method="post" action="conn.asp" onSubmit="return ClickOn()">
<table width="642" border="1" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#666666" bordercolordark="#CCCCCC" bgcolor="#FFFFFF">
<tr>
<td width="126" class="style6"><div align="right">标 题:</div></td>
<td width="510"><input name="title" type="text" class="text" id="title"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">昵 称:</div></td>
<td><input name="name" type="text" class="text" id="name"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">O I C Q:</div></td>
<td><input name="qq" type="text" class="text" id="qq"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">头 像:</div></td>
<td><img src="txr.jpg" width="120" height="113"> <img src="txy.gif" width="120" height="113"> <img src="txs.jpg" width="120" height="113"> <img src="txsi.jpg" width="120" height="113"><br>
<input name="tx" type="radio" value="txr.jpg" checked>
<input type="radio" name="tx" value="txy.gif">
<input type="radio" name="tx" value="txs.jpg">
<input type="radio" name="tx" value="txsi.jpg"></td>
</tr>
<tr>
<td width="126" class="style6"><div align="right">内 容:</div></td>
<td><textarea name="content" class="bg" id="content"></textarea></td>
</tr>
<tr>
<td colspan="2" class="style6">
<div align="center">
<input name="Submit" type="submit" class="tijiao" value="提交">
<input name="Submit" type="reset" class="tijiao" value="取消">
</div>
<div align="right"> </div></td>
</tr>
</table>
</form>
</body>
</html>
展开全部
<from>标签下有个action="处理程序文件名"的属性的,你写一个处理程序就行了。写这一类的程序可以用jsp,asp等语言。
asp+access:
DBPath = Server.MapPath("数据库名")
set cn=Server.CreateObject("ADODB.Connection")
cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &DBPath
asp+access:
DBPath = Server.MapPath("数据库名")
set cn=Server.CreateObject("ADODB.Connection")
cn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &DBPath
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
高中学数据库?太强了吧,呵呵.
需要一个发送表单的页面,像楼上两位这种.然后后台需要一个接收的页面,里面写程序负责把接收到的数据保存到数据库里
需要一个发送表单的页面,像楼上两位这种.然后后台需要一个接收的页面,里面写程序负责把接收到的数据保存到数据库里
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要链接数据库必须要用程序,用DW一样要写程序来实现。
用类似以下的程序来写:
dim conn
dim rsconn
set conn=server.createobject("adodb.connection")
conn.open dsn,uid,pwd
set rsconn=conn.execute(SQL语句)
conn.close
另一种方法
function changechr(str)
changechr=replace(replace(replace(replace(str,"<","<"),">",">"),chr(13),"<br>")," "," ")
end function
OR
function HTMLEncode2(fString)
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "<BR>")
HTMLEncode2 = fString
end function
在存进数据库时
比如:
rs("文章内容")=HTMLEncode2(request("msg"))
rs.update
用类似以下的程序来写:
dim conn
dim rsconn
set conn=server.createobject("adodb.connection")
conn.open dsn,uid,pwd
set rsconn=conn.execute(SQL语句)
conn.close
另一种方法
function changechr(str)
changechr=replace(replace(replace(replace(str,"<","<"),">",">"),chr(13),"<br>")," "," ")
end function
OR
function HTMLEncode2(fString)
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "<BR>")
HTMLEncode2 = fString
end function
在存进数据库时
比如:
rs("文章内容")=HTMLEncode2(request("msg"))
rs.update
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询