Thread: Error Message

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    NIG
    Posts
    4
    Rep Power
    0

    Question Error Message


    Hi all,

    I have two forms, form1 and form2, form1 receives a phone number POST it to form2 which select from an MS SQL DB and populate form2.

    My problem is I want an alert or a meaningfull Error message to be displayed when a user enters a phone number that is not in the Database , below is my piece of code for the form that is getting populate;

    <%
    category = TRIM( Request.Form( "cat" ) )
    username = TRIM( Request.Form( "username" ) )



    IF username <> "" THEN
    Set Con = Server.CreateObject( "ADODB.Connection" )
    Con.Open "PROVIDER=SQLOLEDB;DATA SOURCE=ABD;UID=sa;PWD=abd;DATABASE=abdul"
    Set RS= Server.CreateObject( "ADODB.Recordset" )

    If category = "Globe" then
    RS.Open "select * from globe where phonenum = '" &username& "'", Con

    firstname = RS.Fields("firstname")
    lastname = RS.Fields("lastname")
    middlename = RS.Fields("middlename")
    homeadd = RS.Fields("homeadd")
    busadd = RS.Fields("busadd")
    terrifplan = RS.Fields("terrifplan")
    state = RS.Fields("state")
    phonenum = RS.Fields("phonenum")
    typeofpay = RS.Fields("typeofpay")
    assignedto = RS.Fields("assignedto")
    nservicereq = RS.Fields("nservicereq")
    //Comment = RS.Fields("Comment")


    End if
    Con.Close
    Set RS = Nothing
    Set Con = Nothing
    END IF
    %>


    Thanks

    Abd
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0
    You need to ask, after your "RS.Open" if at EOF and if so do a Response.write message.

    Here's how I do it to check for existing SSN in a database;

    rs.open "Select * From tblStudents Where SSN = " & Request.Form("SSN"), con, adOpenKeyset, adLockOptimistic
    If rs.EOF Then
    rs.addnew
    'code to add new data
    Else
    response.write("<BR>This SSN Already Exists in the Database. The next page will show the existing record.")
    End If

    I then open up the page that allows for editing of the data showing the existing record.

    Hope this helps.

IMN logo majestic logo threadwatch logo seochat tools logo