主题:  常见问题这里来提

guchao911

职务:普通成员
等级:1
金币:0.0
发贴:64
注册:2004/12/18 16:01:52
#312005/1/27 14:37:56
引用:
Session是字符串变量,而arrCart是数组,类型不符。
可以把数据组存存如"a1,a2,a3"这样的字符串在Session中,用时用split函数,把字符串抉择分成数组。


请具体点好吗,举个例子,分别写一下数组赋值给session,和session赋值给数组,谢谢了!



蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
注册:2001/12/20 15:57:57
#322005/1/27 14:59:21
strTemp = ""

for i = 0 to UBound(arrCat)
    if strTemp = "" then
        strTemp = strTemp & arrCat(i)
    else
        strTemp = "|" & strTemp
    end if
next

Session("MyCat") = strTemp

上函数可用join更简单:join(arrCat, "|"),ASP中是否有没有,我测试过,试一下。

从Session中取得值,并放入数组中
strTemp = Session("MyCat")
arrCat = split(strTemp, "|")

编辑历史:[此帖最近一次被 蓝鲸 编辑过(编辑时间:2005-01-27 15:11:09)]

非常大鱼

guchao911

职务:普通成员
等级:1
金币:0.0
发贴:64
注册:2004/12/18 16:01:52
#332005/1/27 15:20:01
谢谢蓝鲸了,
但我需要的是二位数组,有关网上购物的,请蓝鲸老兄再写一下



蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
注册:2001/12/20 15:57:57
#342005/1/27 15:49:32
二位数组应该是一位数组的分组,如(2,4,6,8),分组变成((2,4),(6,8))。
不过多维数组我没试过,以试验为准。


非常大鱼

xs2004

职务:普通成员
等级:1
金币:0.0
发贴:23
注册:2004/12/1 8:41:11
#352005/1/27 17:08:44
我的那个乱码问题是不是解决不了?


可是我找找了,一个关联文件后缀为.INC的文件里面的代码是这样子写的,会不会是这里出错了那又要怎么改过来?
<%
function htmlencode2(str)
dim result
dim l
if isNULL(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"&lt;"
case ">"
result=result+"&gt;"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"&quot;"
case "&"
result=result+"&amp;"
case chr(32)
'result=result+"&nbsp;"
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+"&nbsp;"
else
result=result+" "
end if
else
result=result+"&nbsp;"
end if
case chr(9)
result=result+" "
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
%>



蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
注册:2001/12/20 15:57:57
#362005/1/27 21:53:18
这段代码已经很明显了,是把输入符号转化成特定字符。如果不想转化,就不要用这个函数,建议先打下扎实的编程基本,看些好书。对初学者,我是不推荐看网上下载代码的,一是好的代码都很深,而很多普通代码有误导作用。


非常大鱼

xs2004

职务:普通成员
等级:1
金币:0.0
发贴:23
注册:2004/12/1 8:41:11
#372005/1/28 9:12:43
这段代码能不能帮我改一下,错在哪了,我看不太懂呀。

<%
function htmlencode2(str)
dim result
dim l
if isNULL(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "<"
result=result+"&lt;"
case ">"
result=result+"&gt;"
case chr(13)
result=result+"<br>"
case chr(34)
result=result+"&quot;"
case "&"
result=result+"&amp;"
case chr(32)
'result=result+"&nbsp;"
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+"&nbsp;"
else
result=result+" "
end if
else
result=result+"&nbsp;"
end if
case chr(9)
result=result+" "
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
%>



蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
注册:2001/12/20 15:57:57
#382005/1/28 12:55:10
用Replace更简单些
Result = Replace(Result, "chr(13)", "<br>")


非常大鱼

rvvlove

职务:普通成员
等级:1
金币:0.0
发贴:30
注册:2004/6/7 12:22:27
#392005/1/28 13:03:49
<%
Option Explicit
dim a
a=2
response.write a
%>
为什么强制声明变量就出错啊.
错误类型:
Microsoft VBScript 编译器错误 (0x800A0400)
/1.asp, 第 10 行
Option Explicit



蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
注册:2001/12/20 15:57:57
#402005/1/28 13:08:31
问题不是出在前几行,看出错信息是第10行,加上Option Explicit后,每个变量必须事先定义,看第10行是否用了没有定义的变量


非常大鱼

rvvlove

职务:普通成员
等级:1
金币:0.0
发贴:30
注册:2004/6/7 12:22:27
#412005/1/28 13:11:22
9 <%
10 Option Explicit
11 dim a
12 a=2
13 response.write a
14 %>
就这样了,跟本就不应该出错的,是不是我的DW软件坏了啊



rvvlove

职务:普通成员
等级:1
金币:0.0
发贴:30
注册:2004/6/7 12:22:27
#422005/1/28 13:27:47
我搞定了,<%option explicit%>
HTML页写在第一行,ASP页写在<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>后紧接一行也就是第二行就全OK了



缺缺

职务:管理员
等级:8
金币:41.0
发贴:9620
注册:2004/1/14 19:14:47
#432005/1/28 13:32:03
Option Explicit必须放在文档的最上面


程序不是由DW来执行,出错怎么说DW的问题呢?



xs2004

职务:普通成员
等级:1
金币:0.0
发贴:23
注册:2004/12/1 8:41:11
#442005/1/29 9:18:25
是不是这样子写,不过我试了还不太行:再请高手指点!
<%
Function htmlencode2(strer)
If not isNull(strer) and strer <> "" Then
strer=replace(strer,"<","&lt;")
strer=replace(strer,">","&gt;")
strer=replace(strer," ","&nbsp;")
strer=Replace(strer, "'", "&quot;")
strer=Replace(strer, """", "&quot;")
strer=replace(strer,vbCrLf,"<br>")
End If
htmlencode2=strer
End Function
%>



xs2004

职务:普通成员
等级:1
金币:0.0
发贴:23
注册:2004/12/1 8:41:11
#452005/1/29 9:36:07
char.inc代码是
<%
Function htmlencode2(strer)
If not isNull(strer) and strer <> "" Then
strer=replace(strer,"<","&lt;"
strer=replace(strer,">","&gt;"
strer=replace(strer," ","&nbsp;"
strer=Replace(strer, "'", "&quot;"
strer=Replace(strer, """", "&quot;"
strer=replace(strer,vbCrLf,"<br>"
End If
htmlencode2=strer
End Function
%>


下面这段代码会不会出有错误:问题是不是出在红色部分
<!--#include file="char.inc"-->
<%
if session("admin_name"="" then response.end
set rs=server.createobject("adodb.recordset"%>

<!--#include file="conn.asp"--><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href=../css.css rel=STYLESHEET type=text/css>
</head>
<%
if request("action"="save" then
hw_name=request("hw_name"
hw_content=htmlencode2(request("hw_content")
    hw_content2=htmlencode2(request("hw_content2")
hw_cash=request("hw_cash"
hw_pic=request("hw_pic"
    chubsh=request("chubsh"
    zhuang=request("zhuang"
    yeshu=request("yeshu"
    isbn=request("isbn"
sort_id=request("sort_id"
Nsort_id=request("Nsort_id"
company=request("company"
pifa=request("pifa"
daili=request("daili"
hwsn=request("hwsn"
data=request("data"
kaiben=request("kaiben"
tuijian=request("tuijian"
jia=request("jia"
if not(isnumeric(hw_cash)) then
errmsg="<br>"+"<li>价格应该为数字"
founderr=true
end if
if hw_name="" then
errmsg=errmsg+"<br>"+"<li>名称不能为空"
founderr=true
end if
if hw_content="" then
errmsg=errmsg+"<Br>"+"<li>介绍不能为空"
founderr=true
end if
if sort_id="" then
errmsg=errmsg+"<br>"+"<li>类别不能为空"
founderr=true
end if

if nsort_id="" then
errmsg=errmsg+"<br>"+"<li>类别不能为空"
founderr=true
end if
if hw_pic="" then hw_pic="img/noimage.gif"

if founderr=true then
response.write errmsg
response.write "<br>"
response.write "<a href=addhw.asp>返回</a>"
response.end
else
hw_name=server.htmlencode(hw_name)
hw_name=replace(hw_name," ","&nbsp;"
hw_name=replace(hw_name,chr(13)&chr(10),"<Br>"


hw_content=server.htmlencode(hw_content)
hw_content=replace(hw_content," ","&nbsp;"
hw_content=replace(hw_content,chr(13)&chr(10),"<Br>"

hw_pic=server.htmlencode(hw_pic)

sql="select * from hw"
rs.open sql,conn,3,3
rs.addnew
rs("hw_name"=hw_name
rs("hw_content"=hw_content
        rs("hw_content2"=hw_content2
rs("hw_cash"=hw_cash
rs("sort_id"=sort_id
rs("Nsort_id"=Nsort_id
rs("company"=company
rs("daili"=daili
rs("pifa"=pifa
rs("hw_sn"=hwsn
     rs("chubsh"=chubsh
     rs("kaiben"=kaiben
     rs("yeshu"=yeshu
     rs("data"=data
     rs("isbn"=isbn
     rs("zhuang"=zhuang
rs("hw_pic"=hw_pic
rs("tuijian"=tuijian
rs("jia"=jia
rs.update
end if
response.write "货物添加成功"
response.write "<br>"
response.write "<a href=addhw.asp>返回</a>"
rs.close


else
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<title>添 加 商 品</title>
<link rel="stylesheet" type="text/css" href="style.css">
<%
dim count

set rs=server.createobject("adodb.recordset"
sql = "select * from Nsort order by Nsort_id asc"
rs.open sql,conn,1,1
%>
<script language = "javascript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("Nsort_name")%>","<%= trim(rs("sort_id")%>","<%= trim(rs("Nsort_id")%>";
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;

function changelocation(locationid)
{
document.myform.Nsort_id.length = 0;

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

}
</script>
</head>

<body>
<tr>
<td>
<div align="center"><b>所有选项都必须填写</b></div>
</td>
</tr>
<form method="POST" name="myform" action="addhw.asp?action=save">
<table class="border" cellspacing="0" width="80%" border="0" cellpadding="4" cellspacing="0" >

<tr align="center">
<td class="tdbg" width="100%">
    <table border="0" cellspacing="1" width="100%">

<td width="85%">
<%
sql = "select * from sort"
rs.open sql,conn,1,1
    if rs.eof and rs.bof then
    response.write "请先添加栏目。"
    response.end
    else%>
<select name="sort_id" onChange="changelocation(document.myform.sort_id.options[document.myform.sort_id.selectedIndex].value)" size="1">
<option selected value="<%=trim(rs("sort_id")%>"><%=trim(rs("sort_name")%></option>
<% dim selclass
selclass=rs("sort_id"
rs.movenext
do while not rs.eof
%> <option value="<%=trim(rs("sort_id")%>"><%=trim(rs("sort_name")%></option>
<%rs.movenext
loop
    end if
rs.close
%></select>
<select name="Nsort_id">
<%sql="select * from Nsort where sort_id="&selclass
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
%>
<option selected value="<%=rs("Nsort_ID"%>"><%=rs("Nsort_name"%></option>
<% rs.movenext
do while not rs.eof%>
<option value="<%=rs("Nsort_ID"%>"><%=rs("Nsort_name"%></option>
<% rs.movenext
loop
end if
rs.close
set rs = nothing%>
</td>
</tr>
</table>

<table border="0" width="500" cellspacing="1" height="392" align="left">
<tr>
<td width="100%" height="395">

<table border="0" width="100%" cellspacing="1">
<tr>
<td colspan="2"><font color="#FF0000">型号名称</font>
<input type="text" name="hw_name" size="20" class=input>
<font color="#FF0000"> &nbsp;&nbsp;&nbsp;&nbsp; </font> </td>
</tr>
<tr>
<td colspan="2"><font color="#FF0000">市场价</font>
<input type="text" name="pifa" size="7" class=input>
元 <font color="#FF0000">&nbsp;&nbsp;&nbsp;会员价</font>
<input type="text" name="hw_cash" size="7" class=input>
元 <font color="#FF0000">&nbsp;&nbsp;&nbsp;&nbsp;VIP价</font>
<input type="text" name="daili" size="7" class=input>
元 </td>
</tr>
<tr>
<td height="5" colspan="2">
<hr noshade size="1">
</td>
</tr>
<tr>
<td><font color="#000000">录入</font>
<input type="text" name="hwsn" size="10" class=input value="不详">
</td>
<td width="63%"><font color="#000000">出品公司</font>
<input type="text" name="chubsh" size="30" class=input value="不详">
</td>
</tr>
<tr>
<td><font color="#000000">尺码</font>
<input type="text" name="kaiben" size="10" class=input value="16">
</td>
<td width="63%"><font color="#000000">出品日期</font>
<input type="text" name="data" size="24" class=input value="2002-10-10">
格式:2002-10-10</td>
</tr>
<tr>
<td><font color="#000000">颜色</font>
<input type="text" name="yeshu" size="10" class=input value="100">
</td>
<td width="63%"><font color="#000000">编号</font>
<input type="text" name="isbn" size="30" class=input value="不详">
</td>
</tr>
<tr>
<td height="5" colspan="2">
<hr noshade size="1">
</td>
</tr>
<tr>
<td colspan="2"> <font color="#000000">包装类型</font>
<input type="text" name="zhuang" size="30" class=input value="普通">
</td>
</tr>
<tr>
<td colspan="2"> <font color="#FF0000">简单内容介绍</font></td>
</tr>
<tr>
<td valign="top" colspan="2">
<textarea rows="3" name="hw_content" cols="50" class=input>暂时没有……</textarea>
</td>
</tr>
<tr>
<td valign="top" colspan="2"><font color="#FF0000">详细内容介绍</font></td>
</tr>
<tr>
<td valign="top" colspan="2">
<textarea rows="10" name="hw_content2" cols="50" class=input>暂时没有……</textarea>
</td>
</tr>
<tr>
<td colspan="2"> <font color="#FF0000">商品图片</font>
<input type="text" name="hw_pic" size="46" class=input value="pic/">
<a href="upfile.asp" target="_blank">上传图片</a></td>
</tr>
</table>
<table width="372" border="0" cellspacing="0" cellpadding="0" height="24">
<tr>
<td>推荐此商品
<input type="radio" name="tuijian" value="-1">
不推荐
<input type="radio" name="tuijian" value="0" checked>
<br>
否特价
<input name="jia" type="radio" value="0" checked>
&nbsp;&nbsp; 是特价
<input type="radio" name="jia" value="1">
</td>
</tr>
</table>
<input type="hidden" name="act" value="upload">
<input type="hidden" name="upcount" value="1">
<p>
<input type="submit" value="提交" name="B1" class=input>
<input type="reset" value="全部重写" name="B2" class=input>
</p>


</td>
</tr>
</table>
</form>

</body>
</html>

<%end if%>