写入数据库失败!!急

thesoup 2009-04-09 11:45:09
除"tuijian"字段无法写入数据库外,其他都可以,代码哪里出错了?

<%
id=Trim(Request.Form("id"))
User=Trim(request.form("User"))
Hits=Trim(request.form("Hits"))
BigClassName=trim(request.form("BigClassName"))
SmallClassName=trim(request.form("SmallClassName"))
content=trim(request.form("content"))
Passed=trim(request.form("Passed"))
tuijian=trim(request.form("tuijian"))
dateTime=trim(request.form("dateTime"))
action=request("action")
title=request("title")
if BigClassName="" then
founderr=true
errmsg=errmsg+"<li>未指定新闻所属大类</li>"
end if
if Title="" then
founderr=true
errmsg="<li>新闻标题不能为空</li>"
end if
if Content="" then
founderr=true
errmsg=errmsg+"<li>新闻内容不能为空</li>"
end if

if founderr=false then
Title=dvhtmlencode(Title)
if Infotime<>"" and IsDate(Infotime)=true then
Infotime=CDate(Infotime)
else
Infotime=now()
end if

if Hits<>"" then
Hits=CLng(Hits)
else
Hits=0
end if

set rs=server.createobject("adodb.recordset")
select case Action
case "Add"
sql="select * from News where (id is null)"
rs.open sql,conn,1,3
rs.addnew
call SaveData()
rs.update
rs.close
set rs=nothing
response.redirect "News_Manage.asp"
case "Modify"
if ID<>"" then
sql="select * from News where id="&ID
rs.open sql,conn,1,3
if not (rs.bof and rs.eof) then

call SaveData()
rs.update
rs.close
set rs=nothing
response.redirect "News_Manage.asp"
else
founderr=true
errmsg=errmsg+"<li>找不到此新闻,可能已经被删除。</li>"
call WriteErrMsg()
end if
else
founderr=true
errmsg=errmsg+"<li>不能确定ID的值</li>"
call WriteErrMsg()
end if
Case else
founderr=true
errmsg=errmsg+"<li>没有选定参数</li>"
call WriteErrMsg()
end select
call CloseConn()
else
WriteErrMsg
end if
%>

<%
sub SaveData()
rs("Title")=Title
rs("Content")=Content
rs("User")=User
rs("BigClassName")=bigclassname
rs("SmallClassName")=SmallClassName
rs("datetime")=datetime
rs("Hits")=Hits
if tuijian="true" then
rs("tuijian")=true
else
rs("tuijian")=false
end if
if Passed="true" then
rs("Passed")=true
else
rs("Passed")=false
end if

rs("DefaultPicUrl")=DefaultPicUrl
end sub
%>
...全文
324 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
thesoup 2009-04-13
  • 打赏
  • 举报
回复
找不出问题。。转用了文本型来做,还是谢谢大家的帮助。结贴!
晨晨 2009-04-10
  • 打赏
  • 举报
回复
如果在数据库中你定义的这个字段是布尔型的,在保存的时候,要转成整型0/1来存,从你的代码来看,肯定得到了值的.
thesoup 2009-04-10
  • 打赏
  • 举报
回复
以上方法还是不行,不知是哪里出错。。还是我的空间有问题!
我的QQ是276646204 我可以把 添加 修改 保存页面都发过去 ,麻烦你们加我,帮帮忙,谢谢!
zb1999 2009-04-10
  • 打赏
  • 举报
回复
不好意思~~
sql="select * from News where (id is null)"
rs.open sql,conn,1,3
rs.addnew
call SaveData()
rs.update

忘记改了...
<%
id=Trim(Request.Form("id"))
User=Trim(request.form("User"))
Hits=Trim(request.form("Hits"))
BigClassName=trim(request.form("BigClassName"))
SmallClassName=trim(request.form("SmallClassName"))
content=trim(request.form("content"))
Passed=trim(request.form("Passed"))
tuijian=trim(request.form("tuijian"))
dateTime=trim(request.form("dateTime"))
action=request("action")
title=request("title")
if BigClassName="" then
founderr=true
errmsg=errmsg+" <li>未指定新闻所属大类 </li>"
end if
if Title="" then
founderr=true
errmsg=" <li>新闻标题不能为空 </li>"
end if
if Content="" then
founderr=true
errmsg=errmsg+" <li>新闻内容不能为空 </li>"
end if

if founderr=false then
Title=dvhtmlencode(Title)
if Infotime <>"" and IsDate(Infotime)=true then
Infotime=CDate(Infotime)
else
Infotime=now()
end if

if Hits <>"" then
Hits=CLng(Hits)
else
Hits=0
end if

set rs=server.createobject("adodb.recordset")
select case Action
case "Add"
sql="select * from News where (id is null)"
rs.open sql,conn,1,3
rs.addnew
''call SaveData()
call SaveData(Title,Content,User,bigclassname,SmallClassName,datetime,Hits,tuijian)
rs.update
rs.close
set rs=nothing
response.redirect "News_Manage.asp"
case "Modify"
if ID <>"" then
sql="select * from News where id="&ID
rs.open sql,conn,1,3
if not (rs.bof and rs.eof) then

''call SaveData()
call SaveData(Title,Content,User,bigclassname,SmallClassName,datetime,Hits,tuijian)

rs.update
rs.close
set rs=nothing
response.redirect "News_Manage.asp"
else
founderr=true
errmsg=errmsg+" <li>找不到此新闻,可能已经被删除。 </li>"
call WriteErrMsg()
end if
else
founderr=true
errmsg=errmsg+" <li>不能确定ID的值 </li>"
call WriteErrMsg()
end if
Case else
founderr=true
errmsg=errmsg+" <li>没有选定参数 </li>"
call WriteErrMsg()
end select
call CloseConn()
else
WriteErrMsg
end if
%>

<%
sub SaveData(Title,Content,User,bigclassname,SmallClassName,datetime,Hits,tuijian)
rs("Title")=Title
rs("Content")=Content
rs("User")=User
rs("BigClassName")=bigclassname
rs("SmallClassName")=SmallClassName
rs("datetime")=datetime
rs("Hits")=Hits
if tuijian="true" then
rs("tuijian")=true
else
rs("tuijian")=false
end if
if Passed="true" then
rs("Passed")=true
else
rs("Passed")=false
end if

rs("DefaultPicUrl")=DefaultPicUrl
end sub
%>
zb1999 2009-04-10
  • 打赏
  • 举报
回复
<%
id=Trim(Request.Form("id"))
User=Trim(request.form("User"))
Hits=Trim(request.form("Hits"))
BigClassName=trim(request.form("BigClassName"))
SmallClassName=trim(request.form("SmallClassName"))
content=trim(request.form("content"))
Passed=trim(request.form("Passed"))
tuijian=trim(request.form("tuijian"))
dateTime=trim(request.form("dateTime"))
action=request("action")
title=request("title")
if BigClassName="" then
founderr=true
errmsg=errmsg+" <li>未指定新闻所属大类 </li>"
end if
if Title="" then
founderr=true
errmsg=" <li>新闻标题不能为空 </li>"
end if
if Content="" then
founderr=true
errmsg=errmsg+" <li>新闻内容不能为空 </li>"
end if

if founderr=false then
Title=dvhtmlencode(Title)
if Infotime <>"" and IsDate(Infotime)=true then
Infotime=CDate(Infotime)
else
Infotime=now()
end if

if Hits <>"" then
Hits=CLng(Hits)
else
Hits=0
end if

set rs=server.createobject("adodb.recordset")
select case Action
case "Add"
sql="select * from News where (id is null)"
rs.open sql,conn,1,3
rs.addnew
call SaveData()
rs.update
rs.close
set rs=nothing
response.redirect "News_Manage.asp"
case "Modify"
if ID <>"" then
sql="select * from News where id="&ID
rs.open sql,conn,1,3
if not (rs.bof and rs.eof) then

''call SaveData()
call SaveData(Title,Content,User,bigclassname,SmallClassName,datetime,Hits,tuijian)

rs.update
rs.close
set rs=nothing
response.redirect "News_Manage.asp"
else
founderr=true
errmsg=errmsg+" <li>找不到此新闻,可能已经被删除。 </li>"
call WriteErrMsg()
end if
else
founderr=true
errmsg=errmsg+" <li>不能确定ID的值 </li>"
call WriteErrMsg()
end if
Case else
founderr=true
errmsg=errmsg+" <li>没有选定参数 </li>"
call WriteErrMsg()
end select
call CloseConn()
else
WriteErrMsg
end if
%>

<%
sub SaveData(Title,Content,User,bigclassname,SmallClassName,datetime,Hits,tuijian)
rs("Title")=Title
rs("Content")=Content
rs("User")=User
rs("BigClassName")=bigclassname
rs("SmallClassName")=SmallClassName
rs("datetime")=datetime
rs("Hits")=Hits
if tuijian="true" then
rs("tuijian")=true
else
rs("tuijian")=false
end if
if Passed="true" then
rs("Passed")=true
else
rs("Passed")=false
end if

rs("DefaultPicUrl")=DefaultPicUrl
end sub
%>
落日听风 2009-04-10
  • 打赏
  • 举报
回复
还没好呢?
rokerker 2009-04-10
  • 打赏
  • 举报
回复
都是的
选和不选都反应进去了
thesoup 2009-04-10
  • 打赏
  • 举报
回复
我的IIS有问题,无法测试呢!
你那边的数据库也是access?tuijian字段也是 是/否 型的号,默认值是False 吗?
rokerker 2009-04-10
  • 打赏
  • 举报
回复
我是本地测试的
你也本地测试一把看看怎么样
如果本地可以空间上不行就是空间问题

急着结束就改掉字段类型吧
thesoup 2009-04-10
  • 打赏
  • 举报
回复
你那边测试也可以吗?
我已上传到空间的,添加资料后 把数据库下载后打开看还是没有选上,其他资料都写入了,就是这个复选框没有选上
rokerker 2009-04-10
  • 打赏
  • 举报
回复
就是把函数改成下面这个样子

<%
sub SaveData()
rs("Title")=Title
rs("Content")=Content
rs("User")=User
rs("BigClassName")=bigclassname
rs("SmallClassName")=SmallClassName
rs("datetime")=datetime
rs("Hits")=Hits
If IsNull(request.form("tuijian")) Or Trim(request.form("tuijian"))="" Then
rs("tuijian")=False
Else
rs("tuijian")=True
End If

rs("Passed")=False

rs("DefaultPicUrl")=DefaultPicUrl
end sub
%>


其余代码不动,
前面一个页面中
<input name="tuijian" type="checkbox" id="tuijian" value="choosed">

写法是对的,现在也在form内部
rokerker 2009-04-10
  • 打赏
  • 举报
回复

If IsNull(request.form("tuijian")) Or Trim(request.form("tuijian"))="" Then
rs("tuijian")=False
Else
rs("tuijian")=True
End If



就是这样写的
注意False 和True的写法,第一个字母大写

在你运行的时候,先把access数据库关掉
运行完了再打开看结果
thesoup 2009-04-10
  • 打赏
  • 举报
回复
这是整个 添加文件:


<!--#include file="conn.asp"-->
<!--#include file="Inc/Function.asp"-->
<%
dim rs
dim sql
dim count
set rs=server.createobject("adodb.recordset")
sql = "select * from newsmallclass order by id asc"
rs.open sql,conn,1,1
%>
<script language = "JavaScript">
var onecount;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassName"))%>","<%= trim(rs("SmallClassName"))%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;

function changelocation(locationid)
{
document.myform.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}

function AddItem(strFileName){
document.myform.IncludePic.checked=true;
document.myform.DefaultPicUrl.value=strFileName;
document.myform.DefaultPicList.options[document.myform.DefaultPicList.length]=new Option(strFileName,strFileName);
document.myform.DefaultPicList.selectedIndex+=1;
if(document.myform.UploadFiles.value==''){
document.myform.UploadFiles.value=strFileName;
}
else{
document.myform.UploadFiles.value=document.myform.UploadFiles.value+"|"+strFileName;
}
}

function CheckForm()
{
if (editor.EditMode.checked==true)
document.myform.Content.value=editor.HtmlEdit.document.body.innerText;
else
document.myform.Content.value=editor.HtmlEdit.document.body.innerHTML;

if (document.myform.title.value.length == 0) {
alert("信息标题没有填写.");
document.myform.title.focus();
return false;
}
if (document.myform.BigClassName.value.length == 0) {
alert("信息大类没有选");
document.myform.BigClassName.focus();
return false;
}

if (document.myform.user.value.length == 0) {
alert("信息发布人没有填写");
document.myform.user.focus();
return false;
}
return true;
}
</script>


<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top">
<table width="95%" border="0" cellpadding="2" cellspacing="1" class="table_southidc">
<form method="POST" name="myform" onSubmit="return CheckForm();" action="News_save.asp?action=Add" target="_self">
<tr>
<td class="back_southidc" height="30" colspan="2" align="center">增加信息</td>
</tr>
<tr bgcolor="#ECF5FF">
<td width="119" height="25"><font color="#FF0000">*</font>信息标题:</td>
<td width="476"> <input name="title" type="text" class="input" size="50" maxlength="200"></td>
</tr>
<tr bgcolor="#ECF5FF">
<td height="25"><font color="#FF0000">*</font>信息类别:</td>
<td>
<%
sql = "select * from newbigclass"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "请先添加栏目。"
else
%>
<select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)" size="1">
<option selected value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
<%
dim selclass
selclass=rs("BigClassName")
rs.movenext
do while not rs.eof
%>
<option value="<%=trim(rs("BigClassName"))%>"><%=trim(rs("BigClassName"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select> <select name="SmallClassName">
<option value="" selected>不指定小类</option>
<%
sql="select * from newsmallclass where BigClassName='" & selclass & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<% rs.movenext
do while not rs.eof%>
<option value="<%=rs("SmallClassName")%>"><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
<%
ranNum=int(9*rnd)+10
iddata=month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
%>
</select></td>
</tr>
<tr bgcolor="#ECF5FF">
<td height="25" valign="top"><font color="#FF0000">*</font>信息内容:</td>
<td valign="top"> <input type="hidden" name="content" value=""> <iframe ID="eWebEditor1" src="editor/ewebeditor.asp?id=content&style=southidc" frameborder="0" scrolling="no" width="550" HEIGHT="450"></iframe>
</tr>
<tr bgcolor="#ECF5FF">
<td height="25"><font color="#FF0000">*</font>网址:</td>
<td> <input name="user" type="text" class="input" size="60">
格式:http://www.op-world.cn </td>
</tr>
<tr bgcolor="#ECF5FF">
<td height="24" align="right"><div align="left">是否推荐:</div></td>
<td valign="top"><input name="tuijian" type="checkbox" id="tuijian" value="choosed">
是<font color="#0000FF">(如果选中的话将显示最前面)</font></td>
</tr>
<tr>
<td height="30" align="center" bgcolor="#ECF5FF"><div align="left">录入时间:</div></td>
<td height="30" align="center" bgcolor="#ECF5FF"><div align="left">
<input name="AddDate" type="text" id="AddDate" value="<%=now()%>" maxlength="50">
</div></td>
</tr>
<tr>
<td height="30" colspan="2" align="center" bgcolor="#ECF5FF"> <input type="submit" name="Submit" value="提交" class="input">
 
<input type="reset" name="Submit" value="重置" class="input"> </td>
</tr>
</form>
</table></td>
</tr>
</table>
thesoup 2009-04-10
  • 打赏
  • 举报
回复
<input name="tuijian" type="checkbox" id="tuijian" value="choosed">
rokerker 2009-04-10
  • 打赏
  • 举报
回复
还没有解决?
我在本地调的通的
把你前面一个页面的form贴出来看
php_wsd 2009-04-09
  • 打赏
  • 举报
回复
你在写入之前,先将他输出来看看,这样确认它是否得到值
thesoup 2009-04-09
  • 打赏
  • 举报
回复
表单名就是tuijian 是个选择项来的。如果选中就推荐,如果不选中不推荐。。。
添加资料时已选择推荐,但数据库中都没有选中!!
php_wsd 2009-04-09
  • 打赏
  • 举报
回复
tuijian表单名是不是写错了
如果没有,你分别将它输出看看
thesoup 2009-04-09
  • 打赏
  • 举报
回复
求救 ~~
vvlovevv 2009-04-09
  • 打赏
  • 举报
回复
看是不是数据库中数据类型是什么?
其实这样比较简单,设置该字段类型为integer.将checkbox的value设置为1,选中为0,没选为1,
然后在这个添加页面做个判断,应该没问题了!~~
加载更多回复(16)

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧