会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
耿小超的BLOG
绿柳村边何(sea)
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
新学asp
<
%
dim
conn,connstr
On
Error
Resume
Next
set
Conn
=
server.CreateObject(
"
ADODB.Connection
"
)
connstr
=
"
Provider=MSDATASHAPE;Driver={SQL Server};Server=***;Database=***;User ID=***;Password=***
"
conn.Open connstr
%
>
开始在一个文件里放这样的代码,说明数据库的连接
在其他页面
<!--#include file="Config/WebConfig.asp"-->
用这样的代码就声明出数据库的连接
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<!--
#include file="Config/WebConfig.asp"
-->
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
title
>
发布新闻
</
title
>
</
head
>
<
body
>
<
SCRIPT
LANGUAGE
="JavaScript"
>
function
checkadd()
{
if
(document.postart.dtitle.value.length
<
1
)
{
alert(
"
请您填写信息标题!
"
);
document.postart.dtitle.focus();
return
false
;
}
if
(document.postart.dtext.value.length
<
1
)
{
alert(
"
请您填写信息内容!
"
);
document.postart.dtext.focus();
return
false
;
}
if
(document.postart.dtext.value.length
>
120
)
{
alert(
"
请把信息内容的字数控制在120以内!
"
);
document.postart.dtext.focus();
return
false
;
}
}
</
SCRIPT
>
<
SCRIPT
LANGUAGE
="JavaScript"
>
maxLen
=
120
;
function
checkMaxInput(form)
{
if
(form.dtext.value.length
>
maxLen)
form.remLen.value
=
0
;
else
form.remLen.value
=
maxLen
-
form.dtext.value.length;
}
</
script
>
<
form
action
=""
method
="post"
name
="form"
onSubmit
="return checkadd()"
>
<
table
>
<
tr
bgcolor
="#FFFFFF"
>
<
td
width
="15%"
height
="26"
align
="right"
>
新闻标题:
</
td
>
<
td
width
="65%"
height
="26"
><
input
type
="text"
name
="dtitle"
size
="70%"
maxlength
="20"
>
<
font
color
="#FF0000"
>
* 20字以内
</
font
></
td
>
</
tr
>
<
tr
bgcolor
="#FFFFFF"
>
<
td
align
="right"
>
新闻内容:
</
td
>
<
td
><
textarea
rows
="6"
name
="dtext"
cols
="90%"
onKeyDown
="checkMaxInput(this.form)"
onKeyUp
="checkMaxInput(this.form)"
class
="txtl"
maxlength
="120"
></
textarea
>
<
font
color
="#FF0000"
>
*
120字以内
</
font
></
td
>
</
tr
>
<
tr
>
<
td
height
="26"
align
="right"
bgcolor
="#FFFFFF"
>
</
td
>
<
td
height
="26"
bgcolor
="#FFFFFF"
><
font
color
="#FF0000"
>
目前还可以写
<
input
readonly type
=text
name
=remLen
size
=2
maxlength
=2
value
="120"
style
="border: 1 solid #888888"
>
个字
</
font
></
td
>
</
tr
>
<
tr
>
<
td
><
input
type
="submit"
value
="发布"
name
="submit"
></
td
>
</
tr
>
<%
dim
newscontent,newstitle
newscontent
=
replace
(
trim
(Request.Form(
"
dtext
"
)),
"
'
"
,
"
‘
"
)
newstitle
=
replace
(
trim
(Request.Form(
"
dtitle
"
)),
"
'
"
,
"
‘
"
)
if
(newscontent
<>
""
)
then
Sql
=
"
insert into news(title,content) values ('
"
&
newstitle
&
"
','
"
&
newscontent
&
"
')
"
Set
Rs
=
Conn.execute(Sql)
'
Response.Write ("<script>alert('恭喜您!发布成功!');window.close();</script>")
end
if
%>
</
table
>
</
form
>
</
script
>
</
body
>
</
html
>
这样就实现了新闻的添加。
posted on
2007-10-29 21:12
超少
阅读(
172
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部