新学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" > * &nbsp; 120字以内 </ font ></ td >
    
</ tr >
    
< tr >
      
< td  height ="26"  align ="right"  bgcolor ="#FFFFFF" > &nbsp; </ 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 >
这样就实现了新闻的添加。

转载于:https://www.cnblogs.com/gengxiaochao/archive/2007/10/29/942063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值