后台的话就是取得$_POST的值(前面那个name所对应的),然后将取得的值组装成一个新数组(新数组中的键名需和数据库对应的字段名相同),然后生成model对象,保存。
完成。
我用ASP语言+ACCESS来给你讲一个如何建立简单的新闻系统:新闻系统主要分为四个网页:文章添加,文章修改,文章删除,文章显示,还要加一个文章数据库
(1)文章添加(addnews.asp):
<%if session("password")<>"" then%>
<%if request("text1")="" then
response.write "<script language=JavaScript>" &chr(13) &"alert('请输入用户名!')" &"history.back()" &"</script>"
Response.End
end if
name=request("text1")
address=request("text2")
mobile=request("text3")
phone=request("text4")
qq=request("text5")
email=request("text6")
set rs=server.createobject("adodb.recordset")
set rs1=server.createobject("adodb.recordset")
conn = "DBQ=" + server.mappath("employee_information.mdb") + "DefaultDir=DRIVER={Microsoft Access Driver (*.mdb)}"
sql="select * from employee where name='"&name&"'"
rs.Open sql,conn,1,1
if rs.EOF or rs.bof then
sql="insert into employee(name,address,mobile,phone,qq,email) values('"&name&"','"&address&"','"&mobile&"','"&phone&"','"&qq&"','"&email&"')"
rs1.Open sql,conn,1,1
response.write "<script language=JavaScript>" &chr(13) &"alert('信息添加成功!')"&"window.location.href = 'index1.asp'"&" </script>"
set rs1=nothing
else
response.write "<script language=JavaScript>" &chr(13) &"alert('此信息已经添加!')" &"history.back()" &"</script>"
end if
rs.Close
set rs=nothing
%>
<%else
Response.Redirect "20050130_loginagine.asp"
end if%>
(2)文章修改(modifynews.asp):
<%if session("password")<>"" then%>
<!--#include file="conn.asp" -->
<%
id1=request("id")
if request("text1")="" then
response.write "<script language=JavaScript>" &chr(13) &"alert('请输入用户名!')" &"history.back()" &"</script>"
Response.End
end if
name=request("text1")
address=request("text2")
mobile=request("text3")
qq=request("text5")
email=request("text6")
sql="update employee set name='"&name&"',address='"&address&"',mobile='"&mobile&"',qq='"&qq&"',email='"&email&"' where id="+id1
rs.Open sql,conn,1,1
response.write "<script language=JavaScript>" &chr(13) &"alert('记录信息修改成功!')"&"window.location.href = 'index1.asp'"&" </script>"
set rs=nothing
%>
<%else
Response.Redirect "20050130_loginagine.asp"
end if%>
(3)文章删除(del.asp):
<%if session("password")<>"" then%>
<script language="javascript">
function confirmDel(id){
if (confirm("确定这个删除?"))
{
window.location.href = "delnews.asp?id=" + id
}
}
</script>
<!--#include file="conn.asp" -->
<%
sql="select * from employee order by qq desc"
rs.open sql,conn,1,3
if rs.EOF then
Response.Write "没记录"
else
%>
<title>25175</title>
<link href="css.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#E7E7E7">
<td width="590" height="25"><A HREF="index1.asp">首页</A><A HREF="add.asp">添加</A> <A HREF="modify.asp">修改</A><a href="SEARCH.ASP">查询</a><a href="delete_all.asp">批量删除</a><a href="del.asp">删除</a><a href="change_password.asp">修改密码</a><a href="20050130_logout.asp">退出</a><a href="admin_modify.asp">版主回复</a></td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#CECFCE">
<td width="100" height="25">
<div align="center">姓名</div></td>
<td width="360">留言</td>
<td width="60">网址</td>
<td width="60">email</td>
<td width="60">QQ</td>
<td width="120"><div align="center"></div></td>
</tr>
</table>
<%do while not rs.EOF%>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="25"><%=rs("name")%></td>
<td width="360"><%=rs("address")%></td>
<td width="60"><%=rs("mobile")%></td>
<td width="60"><%=rs("qq")%></td>
<td width="130"><%=rs("email")%></td>
<td width="25"><a href='javascript:confirmDel(<%= rs("id") %>)'>删除</a> </td>
<td width="25"><div align="center">
</div></td>
</tr>
</table>
<%
rs.MoveNext
loop
end if
rs.Close
set rs=nothing
set conn=nothing
%>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="350" height="20"> </td>
<td>
</td>
</tr>
</table>
<%
else
Response.Redirect "20050130_loginagine.asp"
end if
%>
关于文章如何显示我就不详细讲了....
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)