求助,提交数据时判断数据库中是否有同一信息
求助。要求提交数据的时候判断DistrictID与str_DoorNo 字段值是否与数据库中有相同的,有相同的就提示已存在,没有的话就提交上去,求高手帮忙。
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/adovbs.inc"-->
<!--#include file="../inc/functions.asp"-->
<%
Checklogin()
CheckRight()
%>
<%
dim SaleOrRent
SaleOrRent=Request("SaleOrRent")
if SaleOrRent="" then SaleOrRent="Sale"
if SaleOrRent="Sale" then
Tit="出售"
else
Tit="出租"
end if
'response.write SaleOrRent
dim TmpID,Code,RegName,RegSex,RegIDCard,RegPhone,HouseTypeID
dim RegMbPhone,RegDate,DistrictID,Address,DoorNo,IsValid,Audit,PropertyRightID
dim SaleStatus,Endable,RentStatus
IsValid=0
SaleStatus=-1
Endable=-1
if Request("RentStatus")="" then
RentStatus=-1
else
RentStatus=Request("RentStatus")
end if
TmpID=Request("TmpID")
if TmpID="" then TmpID=0
function SaveData(id)
'response.write SaleOrRent
if SaleOrRent="Sale" then
Sql="select * from TmpSale where TmpID='"&id&"'"
else
Sql="select * from TmpRent where TmpID='"&id&"'"
end if
Set RS=Server.CreateObject("ADODB.Recordset")
RS.Open Sql,Conn,1,3
if RS.EOF then
RS.AddNew
if SaleOrRent="Sale" then
RS("TmpId")=GetTmpSaleID(Session("CityID"))
else
RS("TmpId")=GetTmpRentID(Session("CityID"))
end if
end if
RS("HouseTypeID")=Request("str_HouseTypeID")
RS("CityID")=Session("CityID")
RS("Code")=Request("Code")
'RS("HostName")=Request("str_HostName")
'RS("HostSex")=Request("HostSex")
'RS("HostIDCard")=Request("strHostIDCard")
'RS("HostPhone")=Request("strHostPhone")
'RS("HostMbPhone")=Request("HostMbPhone")
RS("RegName")=Request("str_RegName")
RS("RegSex")=Request("RegSex")
RS("RegIDCard")=Request("RegIDCard")
RS("RegPhone")=Request("RegPhone")
RS("RegMbPhone")=Request("str_RegMbPhone")
'RS("RegDate")=Request("dteRegDate")
'RS("tuijian")=Request("tuijian")
RS("DistrictID")=Request("DistrictID")
RS("Address")=Request("strAddress")
RS("DoorNo")=Request("str_DoorNo")
'RS("PropertyRightID")=Request("PropertyRightID")
if SaleOrRent="Sale" then
RS("SaleStatus")=Request("SaleStatus")
'response.write "<font color=red>"&SaleOrRent&"</font>"
else
RS("jiegou")=Request("jiegou")
'RS("jiegou")="TEST"
'response.write request("jiegou")
RS("RentStatus")=Request("RentStatus")
'response.write request("RentStatus")
'response.write "<font color=blue>"&SaleOrRent&"</font>"
end if
RS("UserID")=Request("str_UserID")
RS("DptID")=Session("DptID")
RS("IsValid")=Request("IsValid")
RS("Audit")=Request("Audit")
'RS("Remark")=Request("Remark")
RS("Hall")=Request("str_Hall")
RS("Room")=Request("str_Room")
RS("Toilet")=Request("str_Toilet")
RS.Update
'Response.Write Rs("houseid")
'response.write "<input type='button' value='选择房型图' onclick=window.open('fxadd.asp?houseid="&rs("houseid")&"&districtid="&rs("districtid")&"&housetypeid="&rs("housetypeid")&"','','width=800,height=600,scrollbars=yes')>"
'UpdateZXByHouseID(Rs("TmpID"))
'Call SendMessage(Rs("HouseID"),"")
response.Redirect "house_add2.asp?houseid="&RS("Tmpid")&"&SaleOrRent="&SaleOrRent
RS.Close
Set RS=nothing
end function
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>登记房源</title>
<script language="JavaScript" src="../js/form_check.js"></script>
<script language="VBScript" src="../vbs/form_check.vbs"></script>
<script language="javascript" src="../js/calendar.js"></script>
<link rel="stylesheet" href="../css/style.css" type="text/css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function houseCheck(){
var regname,regidcard,hostname,hostidcard,DistrictID,DoorNo;
if (OnSub()!=false) {//先检查一下有效性
regname=document.forms[0].RegName.value;
regidcard=document.forms[0].RegIDCard.value;
hostname=document.forms[0].str_HostName.value;
hostidcard=document.forms[0].strHostIDCard.value;
DistrictID=document.forms[0].DistrictID.value
DoorNo=document.forms[0].DoorNo.value
var popupWin = window.open('houseCheck.asp?SaleOrRent=<%=SaleOrRent%>®name='+regname+'®idcard='+regidcard+"&hostname="+hostname+"&hostidcard="+hostidcard+"&DistrictID="+DistrictID+"&DoorNo="+DoorNo, 'houseCheck_page', 'scrollbars=yes,width=700,height=450');
}
}
function subdistrictid(){
var districtid;
districtid=document.form1.DistrictID.value;
window.open('fxadd.asp?districtid='+districtid,'width=800,height=600,scrollbars=yes');
}
//-->
</script>
<style type="text/css">
<!--
.style1 {
color: #CC0000;
font-weight: bold;
}
-->
</style>
</head>
<body topmargin="0" leftmargin="0" bgcolor="#FFFFCA">
<!--#include file="house_add_menu.asp"-->
<p align=center class="Xsmall">
<b>
<%
Select Case Request("action")
Case "save":
SaveData(HouseID)
Response.Write "<font color=red>保存成功!</font> <a href='house_add.asp?SaleOrRent="&SaleOrRent&"'>返回</a>"
Response.End
end Select
%>
<font color=red><%=Tit%></font>房源登记<br>
</b>请添加登记房源的详细信息:(请注意:有<font color=red>*</font>号处须填写)</p>
<table width=591 border=1 align="center" cellpadding=4 cellspacing=0 class="Xbig" ID="Table1">
<form method="post" action="house_add.asp?action=save&SaleOrRent=<%=SaleOrRent%>" name=form1 onSubmit="return OnSub();" ID="Form1">
<tr>
<td class=cn9> </td>
<td><strong>第一步:添加基本信息</strong></td>
</tr>
<tr>
<td class=cn9>登记人(店员):</td>
<td><select name=str_UserID ID="select">
<option value="">请选择</option>
<%call UserSelect(session("dptid"),session("userid"))%>
</select> </td>
</tr>
<tr>
<td width=121 class=cn9>联系人姓名:<font color=#ff0000>*</font></td>
<td width=454> <input name=str_RegName class="Sborder" size=10 maxlength=10><input type="radio" name="RegSex" value="1" <%if RegSex="" or RegSex="1" then Response.Write "checked"%> ID="Radio3">
男
<input type="radio" name="RegSex" value="2" <%if RegSex="2" then Response.Write "checked"%> ID="Radio4">
女</td>
</tr>
<!--<tr>
<td width=121 class=cn9>联系人性别:</td>
<td width=454> <input type="radio" name="RegSex" value="1" <%if RegSex="" or RegSex="1" then Response.Write "checked"%> ID="Radio3">
男
<input type="radio" name="RegSex" value="2" <%if RegSex="2" then Response.Write "checked"%> ID="Radio4">
女 </td>
</tr>-->
<!--<tr>
<td width=121 class=cn9>联系人身份证:</td>
<td width=454> <input name=RegIDCard class="Sborder" size=18 maxlength=18></td>
</tr>
<tr>
<td width=121 class=cn9>产权证号:</td>
<td width=454> <input name=PropertyRightID class="Sborder" size=18 maxlength=18></td>
</tr>-->
<!-- <tr>
<td width=121 class=cn9>联系人电话:</td>
<td width=454> <input name=RegPhone class="Sborder" size=50 maxlength=50></td>
</tr>-->
<tr>
<td width=121 class=cn9>联系电话:<font color=#ff0000>*</font></td>
<td width=454> <input name=str_RegMbPhone class="Sborder" size=40 maxlength=50></td>
</tr>
<tr>
<td width=121 class=cn9> </td>
<td width=454> </td>
</tr>
<tr>
<td width=121 class=cn9>地址(小区):<font color=#ff0000>*</font></td>
<td width=454> <input name=str_DistrictName class="Sborder" size=15 readonly>
<input type=hidden name=DistrictID class="Sborder"> <img src="../images/magnifier.gif" onMouseOver="this.style.cursor='hand';" onClick="window.open('District_add.asp?cityid=<%=session("cityid")%>','','width=400,height=400,scrollbars=yes')"> <input name=strAddress class="Sborder" size=40 maxlength=100> </td>
</tr>
<!--<tr>
<td width=121 class=cn9>地址:</td>
<td width=454> <input name=strAddress class="Sborder" size=50 maxlength=100> </td>
</tr>-->
<tr>
<td width=121 height="5" class=cn9>楼型:<font color=#ff0000>*</font></td>
<td width=454> <select name=str_HouseTypeID ID="Select1">
<option value="">选择楼型</option>
<%call HouseTypeSelect2(0)%>
</select> <% if SaleOrRent="Rent" then%>
结构:
<select name=jiegou ID="Select2">
<option value="单">单</option>
<option value="套">套</option>
<option value="组">组</option>
<option value="其他">其他</option>
</select> <%end if%></td>
</tr>
<tr>
<td width=121 class=cn9>详细门牌:<font color=#ff0000>*</font></td>
<td width=454> <input name=str_DoorNo class="Sborder" size=20 maxlength=20> </td>
</tr>
[解决办法]
<%
...
sql="select id from table1 where DistrictID='"&DistrictID&"' or str_DoorNo='"&str_DoorNo&"'"
set rs=conn.execute(sql)
if rs.eof and rs.bof then
conn.execute("insert into table1 (DistrictID,str_DoorNo) values('"&DistrictID&"','"&str_DoorNo&"')")
else
response.write "已存在"
end if