www.webdeveloper.com
Results 1 to 5 of 5

Thread: Urgent

  1. #1
    Join Date
    Apr 2004
    Posts
    71

    Urgent

    Hi all,

    I'm asking for adding a record to the database which that's record already available in the database. In this case an error must dislplay for the user to tell him that your record is already availble.....

    this is my code and I tried

    Code:
    <HTML><HEAD>
    
    
    <% 
    Function ChkString(str)	 
    	 	 
    		str = replace(str, "<", "&lt;", 1, -1, 1)
    		str = replace(str, ">", "&gt;", 1, -1, 1)
    	 
    	 ChkString = str
    End Function
    
    
    ModemNo =Request.form("ModemNo")
    DeptCode = trim(ChkString(Request.form("DeptCode")))
    DeptName = trim(ChkString(Request.form("DeptName")))
    CSLNo = trim(ChkString(Request.form("CSLNo")))
    Area = trim(ChkString(Request.form("Area")))
    SiteName = trim(ChkString(Request.form("SiteName")))
    SiteNo = trim(ChkString(Request.form("SiteNo")))
    NC = trim(ChkString(Request.form("NC")))
    CT = trim(ChkString(Request.form("CT")))
    IC = trim(ChkString(Request.form("IC")))
    BU = trim(ChkString(Request.form("BU")))
    
    ConnString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/database/wardialer.mdb")
    
    set my_conn= Server.CreateObject("ADODB.Connection")
    my_Conn.Open ConnString
    set rscheck = my_conn.Execute ("Select ModemNo from Table1 where ModemNo =" & ModemNo & "")
    		
    if rscheck.eof then
    been_here_before="No"
    end if
    
    RScheck.close
    set rs = server.CreateObject("adodb.recordset")	
    if been_here_before="No" then 
    sql ="select * from Table1"
    
    RS.open Sql,my_conn,1,3
    RS.AddNew
    RS("ModemNo")=ModemNo
    RS("DeptCode")=DeptCode
    RS("DeptName")=DeptName
    RS("CSLNo")=CSLNo
    RS("Area")=Area
    RS("SiteName")=SiteName
    RS("SiteNo")=SiteNo
    RS("NC")= NC
    RS("CT")= CT
    RS("IC")= IC
    RS("BU")= BU
    'RS("date")= now()
    RS.update
    		%>
    </HEAD>
    <body bgcolor="#f4f4f4">
    <div align="center"><font color="#000000" size="2" face="Verdana"> <br>
      <br>
      Has Been Processed!! <br>
      modem number is : <%=ModemNo%> &nbsp;, and your depatment is : <%=DeptCode%> 
      </font> </div>
    <p align="center"><font color="#000000"><a href="main1.asp"><font face="Verdana" size="2">Go 
      to main page</font> </a> </font></p>
    <font color="#000000">
    <%
    		else	
    		%><center>
    <div align="center"><font color="#000000" size="2" face="Verdana">Your have already 
      add this modem<br>
      Please add another modem. </font> </div>
    <p align="center"><font color="#000000"><a href="addNew.asp"><font face="Verdana" size="2">Sign 
      up Again! </font> </a> 
      <%
    		end if
    		
    rs.close
    my_conn.Close 
    set my_conn = nothing
    set rs = nothing
    %>
      </font></P>
    </body></HTML>

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    There seems to be some dead code in there. By that i mean code that is not used, but just sits there.. The variable named 'sql', for example.

    Also, conventionally, its good practise to dimension all variables all variables at the top of youre script. And some indenting wouldnt hurt, either. Just for readability and debugging.

    Are you receiving an error when the script is executed?

    Regards.

  3. #3
    Join Date
    Apr 2004
    Posts
    71
    no actually, I don't have any errors

    but as what i said I need to dislplay a message for the user to tell him that your record is already availble.....


    I have first this addnew.asp
    Code:
    <html>
    
    <HEAD>
    
    
    </HEAD>
    
    <body bgcolor=#f4f4f4>
    <form method="post" action="confirm2.asp" name="globe" ID=Form1>
      <div align="center"> 
        <center>
          <font color="#000000" face="Verdana, Arial, Helvetica, sans-serif"><br>
          </font> 
          <table border="0" cellpadding="2" cellspacing="3" width="460">
            <tr> 
              <td width="436" colspan="2"> <p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="3" color="#000000">Please 
                  give us your data.</font></p></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">ModemNo<font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="ModemNo" size="30" ID=Text1>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">DeptCode<font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="DeptCode" size="30" ID=Text2>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">DeptName<font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="DeptName" size="30" ID=Text3>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">CSLNo <font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="CSLNo" size="20" ID=Text4>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Area <font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="Area" size="20" ID=Text5>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">SiteName : <font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="SiteName" size="10" ID=Text11>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">SiteNo <font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="SiteNo" size="10" ID=Text6>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">NC<font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="NC" size="20" ID=text7>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">CT<font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="CT" size="20" ID=text8>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">IC<font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="IC" size="20" ID=Text9>
                </font></td>
            </tr>
            <tr> 
              <td width="111"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif">BU<font color=#993333>*</font></font></td>
              <td width="325"><font color="#000000" size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
                <input type="text" name="BU" size="8" ID=Text10>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                <input id=Submit2 type=submit value="add data " name=B2>
                &nbsp;&nbsp; 
                <input id=Reset2 type=reset value=Cancel name=Cancel1>
                </font></td>
            </tr>
          </table>
        </center>
      </div>
      <p></p>
    </form>
    
    </body>
    
    </html>
    then this add.asp
    Code:
    <HTML><HEAD>
    
    
    <% 
    Function ChkString(str)	 
    	 	 
    		str = replace(str, "<", "&lt;", 1, -1, 1)
    		str = replace(str, ">", "&gt;", 1, -1, 1)
    	 
    	 ChkString = str
    End Function
    
    
    ModemNo =Request.form("ModemNo")
    DeptCode = trim(ChkString(Request.form("DeptCode")))
    DeptName = trim(ChkString(Request.form("DeptName")))
    CSLNo = trim(ChkString(Request.form("CSLNo")))
    Area = trim(ChkString(Request.form("Area")))
    SiteName = trim(ChkString(Request.form("SiteName")))
    SiteNo = trim(ChkString(Request.form("SiteNo")))
    NC = trim(ChkString(Request.form("NC")))
    CT = trim(ChkString(Request.form("CT")))
    IC = trim(ChkString(Request.form("IC")))
    BU = trim(ChkString(Request.form("BU")))
    
    ConnString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/database/wardialer.mdb")
    
    set my_conn= Server.CreateObject("ADODB.Connection")
    my_Conn.Open ConnString
    set rscheck = my_conn.Execute ("Select ModemNo from Table1 where ModemNo =" & ModemNo & "")
    		
    if rscheck.eof then
    been_here_before="No"
    end if
    
    RScheck.close
    set rs = server.CreateObject("adodb.recordset")	
    if been_here_before="No" then 
    sql ="select * from Table1"
    
    RS.open Sql,my_conn,1,3
    RS.AddNew
    RS("ModemNo")=ModemNo
    RS("DeptCode")=DeptCode
    RS("DeptName")=DeptName
    RS("CSLNo")=CSLNo
    RS("Area")=Area
    RS("SiteName")=SiteName
    RS("SiteNo")=SiteNo
    RS("NC")= NC
    RS("CT")= CT
    RS("IC")= IC
    RS("BU")= BU
    'RS("date")= now()
    RS.update
    		%>
    </HEAD>
    <body bgcolor="#f4f4f4">
    <div align="center"><font color="#000000" size="2" face="Verdana"> <br>
      <br>
      Has Been Processed!! <br>
      modem number is : <%=ModemNo%> &nbsp;, and your depatment is : <%=DeptCode%> 
      </font> </div>
    <p align="center"><font color="#000000"><a href="main1.asp"><font face="Verdana" size="2">Go 
      to main page</font> </a> </font></p>
    <font color="#000000">
    <%
    		else	
    		%><center>
    <div align="center"><font color="#000000" size="2" face="Verdana">Your have already 
      add this modem<br>
      Please add another modem. </font> </div>
    <p align="center"><font color="#000000"><a href="addNew.asp"><font face="Verdana" size="2">Sign 
      up Again! </font> </a> 
      <%
    		end if
    		
    rs.close
    my_conn.Close 
    set my_conn = nothing
    set rs = nothing
    %>
      </font></P>
    </body></HTML>

  4. #4
    Join Date
    Apr 2004
    Posts
    71
    Finally I have confirm2.asp
    [CODE]
    finally confirm2.asp
    Code:
    <HTML><HEAD>
    
    
    <% 
    Function ChkString(str)	 
    	 	 
    		str = replace(str, "<", "&lt;", 1, -1, 1)
    		str = replace(str, ">", "&gt;", 1, -1, 1)
    	 
    	 ChkString = str
    End Function
    
    ModemNo = trim(ChkString(Request.form("ModemNo")))
    DeptCode = trim(ChkString(Request.form("DeptCode")))
    DeptName = trim(ChkString(Request.form("DeptName")))
    CSLNo = trim(ChkString(Request.form("CSLNo")))
    Area = trim(ChkString(Request.form("Area")))
    SiteName = trim(ChkString(Request.form("SiteName")))
    SiteNo = trim(ChkString(Request.form("SiteNo")))
    NC = trim(ChkString(Request.form("NC")))
    CT = trim(ChkString(Request.form("CT")))
    IC = trim(ChkString(Request.form("IC")))
    BU = trim(ChkString(Request.form("BU")))
    ModemNoOK = IsNumeric(ModemNo)
    CSLNoOK = IsNumeric(CSLNo)
    SiteNoOK = IsNumeric(SiteNo)
    if  ModemNoOK = FALSE then
    response.write "You didn't enter a modem number as a number. Please try again."
    else 
    if  CSLNoOK = FALSE then
    response.write "You didn't enter the csl number as a number. Please try again."
    else
    if ModemNo = "" then
    Response.Write "Please Enter Your Modem number<br>"
    else
    
    if NC <> "no" and NC <> "yes" then
    Response.Write "Please Enter network Connectivity either yes or no <br>"
    else 
    
    if CT <> "in" and CT <> "out" and CT <> "both" then
    Response.Write "Please Enter connection type either in, out or both <br>"
    else
    
    if IC <> "no" and IC <> "yes" then
    Response.Write "Please Enter Internet Connection either yes or no <br>"
    else 
    
    if BU <> "no" and BU <> "yes" then
    Response.Write "Please Enter Busness Use either yes or no <br>"
    else 
    %>
    
    
    </HEAD>
    <BODY bgColor="#f4f4f4" >
    <P align=center><font 
    color=#000000>Please verify if all your info you supplied is correct! If not hit 
      back and correct.</font></P>
    <center>
      <table border="0" cellpadding="2" cellspacing="3" width="400">
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>ModemNo :</font></td>
          <td ><%=ModemNo%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>DeptCode :</font></td>
          <td ><%=DeptCode%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>DeptName :</font></td>
          <td ><%=DeptName%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>CSLNo :</font></td>
          <td ><%=CSLNo%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>Area :</font></td>
          <td ><%=Area%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>SiteName :</font></td>
          <td ><%=SiteName%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>SiteNo :</font></td>
          <td ><%=SiteNo%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>NC :</font></td>
          <td ><%=NC%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>CT :</font></td>
          <td ><%=CT%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>IC :</font></td>
          <td ><%=IC%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font face="Verdana" size="2" color=#000000>BU :</font></td>
          <td ><%=BU%>&nbsp;</td>
        </tr>
        <tr> 
          <td ><font color="#000000">&nbsp;</font></td>
          <td > <form action=add.asp method="post" ID=Form1>
              <input type=hidden name="ModemNo"value="<%=ModemNo%>" ID=Hidden1>
              <input type=hidden name="DeptCode" value="<%=DeptCode%>" ID=Hidden2>
              <input type=hidden name="DeptName" value="<%=DeptName%>" ID=Hidden3>
              <input type=hidden name="CSLNo" value="<%=CSLNo%>" ID=Hidden4>
              <input type=hidden name="Area" value="<%=Area%>" ID=Hidden5>
              <input type=hidden name="SiteName" value="<%=SiteName%>" ID=Hidden6>
              <input type=hidden name="SiteNo" value="<%=SiteNo%>" ID=Hidden7>
              <input type=hidden name="NC" value="<%=NC%>" ID=Hidden8>
              <input type=hidden name="CT" value="<%=CT%>" ID=Hidden9>
              <input type=hidden name="IC" value="<%=IC%>" ID=Hidden10>
              <input type=hidden name="BU" value="<%=BU%>" ID=Hidden11>
              <input type=submit value="Confirm" ID=Submit1>
            </form></td>
        </tr>
      </table>
    </center>
    <%
    end if
    end if
    end if
    end if
    end if
    end if
    end if
    %>
    </body>
    </HTML>

  5. #5
    Join Date
    Apr 2004
    Posts
    71
    I have this error when the user enter the same record

    [ERROR]
    ADODB.Recordset (0x800A0E78)
    Operation is not allowed when the object is closed.
    add.asp, line 76
    [/ERROR]

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles