如何添加一个功能?

tigeryull 2005-11-25 03:24:48
这是原程序.记录到数据库ticket表的 xuehao里面是以a|b|c|....这样的
如何能让这个页面有个检查功能,当xuehao里面已经有了就不允许再添加了
就好象现在xuehao里面已经有a了,当在再次添加一次a的时候就会弹出alert框说你已经订票了
请各位帮帮忙
谢谢了


<!--#include file="conn.asp" -->
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>订票系统:订票</title>
</head>
<%
Function allto4(k)
if len(k)<4 then
for i=1 to 4-len(k)
allto4=allto4 & "0"
next
end if
allto4=allto4 & k
End Function

Set rs=Server.CreateObject("ADODB.RecordSet")

if Trim(Request.QueryString("action"))="" then
%>
<form name="book" method="POST" action="ticket_book.asp?action=add">
<select size="1" name="ticket" style="font-family: 宋体; font-size: 9pt">
<%
SQL="SELECT id,title,remainnum FROM ticket where remainnum>0 Order by id"
rs.Open SQL,Conn,1,1
if rs.bof and rs.eof then
%>
<option selected>暂时没有可订票的节目 !</option>
<%
else
do while not rs.eof
%>
<option value="<%=rs("id")%>"><%=rs("title") & "  票数:" & rs("remainnum")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>
<br><font style="font-family: 宋体; font-size: 9pt">你的姓名:</font><input type="text" name="student" size="20" style="font-family: 宋体; font-size: 9pt"><br>
<font style="font-family: 宋体; font-size: 9pt">你的学号:</font><input type="text" name="xuehao" size="20" style="font-family: 宋体; font-size: 9pt"><br>
      <input style="font-family: 宋体; font-size: 9pt" type="submit" value="确定" name="B1" onClick="return check();">
<input style="font-family: 宋体; font-size: 9pt" type="reset" value="重填" name="B2">
</form>
<%
else
dim student,xuehao,ranNum,ticketnum
id=trim(Request.Form("ticket"))
student=trim(Request.Form("student"))
xuehao=trim(Request.Form("xuehao"))

Set rs=Server.CreateObject("ADODB.RecordSet")
SQL="SELECT id,title,number,remainnum,student,xuehao,ticketnum FROM ticket where id=" & int(id)
rs.Open SQL,Conn,1,3
ticketnum=id & allto4(rs("number") - rs("remainnum") + 1)

if rs("number")=rs("remainnum") then
rs("student")=student
rs("xuehao")=xuehao
rs("ticketnum")=ticketnum
else
rs("student")=rs("student") & "|" & student
rs("xuehao")=rs("xuehao") & "|" & xuehao
rs("ticketnum")=rs("ticketnum") & "|" & ticketnum
end if
rs("remainnum")=rs("remainnum")-1
rs.update
rs.close
set rs=nothing
response.Write "<script language=javascript>alert('成功!你的观众号是:" & ticketnum & ",须凭此号码取票,请务必记住!领票时间及地点请留意团学时空!');location.href='ticket_book.asp';</script>"
end if
%>



<script LANGUAGE="javascript">
function check()
{
function checkspace(checkstr) {
var str = '';
for(i = 0; i < checkstr.length; i++) {
str = str + ' ';
}
return (str == checkstr);
}
if(checkspace(document.book.student.value)) {
document.book.student.focus();
alert("请填写你的真实姓名!");
return false;
}
if(checkspace(document.book.xuehao.value)) {
document.book.xuehao.focus();
alert("请填写你的真实学号!");
return false;
}
}
</script>
...全文
87 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
tigeryull 2005-11-25
  • 打赏
  • 举报
回复
我实践过啦用InStr就可以拉,把数据库整段东西拉出来和我新添加的字符串比较
这样就行了
skangming 2005-11-25
  • 打赏
  • 举报
回复
那就查“|a|”就可以知道有无啊, xuehao like '%|&keyword&|%'
LifeForCode 2005-11-25
  • 打赏
  • 举报
回复
恩。学习。
改进,可以|a|abc|abcd|这样存数据,instr(string1,"|bc|")这样比较.
没办法就想邪办法
showlin 2005-11-25
  • 打赏
  • 举报
回复
instr是不可取的
很简单的道理
string1="a|abc|abcd"
instr(string1,"bc")=4
但是bc就不符合条件
还是用split
以前写过一个购物车的,判断是否重复订购
道理和skycuilin(小林) 的一样,先分割数组,然后对数组逐个比较,一旦相等,则报错
tigeryull 2005-11-25
  • 打赏
  • 举报
回复
我是用过小林兄的这个方法
但一直报错......
好无奈...
skycuilin 2005-11-25
  • 打赏
  • 举报
回复
漏了重要地,不好意思,自己加进程序里吧,这个是思路
names="user|user1|user2"
name=split("names","|")
for i=0 to ubound(name)
if name(i)<>"user" then
response.write("如果用户名不为user则输出数据")
end if
next
skycuilin 2005-11-25
  • 打赏
  • 举报
回复
names="user|user1|user2"
name=split("names")
for i=0 to ubound(name)
if name(i)<>"user" then
response.write("如果用户名不为user则输出数据")
end if
next
LifeForCode 2005-11-25
  • 打赏
  • 举报
回复
这么长不看了,说思路
添加前先取出 xuehao字段的值,和要添加的字符比较,判断该字符是不是在字段中了,
用instr函数实现判断,若返回值>0,那就弹出对话框,不执行写入数据操作。
ytzz 2005-11-25
  • 打赏
  • 举报
回复
如果是SQL server 数据库,可以用charindex
如果是ACCESS数据库,那只能用split分割RS了

28,391

社区成员

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

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