PDA

View Full Version : Error Message


Abd
03-27-2003, 08:10 AM
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

Thanks
Abd

glenngv
03-27-2003, 08:47 AM
<%
if rs.EOF then

response.write"<script language=""javascript"">" & VbCrLf
response.write"alert('Entered phone number does not exist!');" & VbCrLf
response.write"</script>" & VbCrLf

else

'display info

end if
%>

where rs is the recordset that retrieves data based on the entered phone number.

Abd
03-27-2003, 09:15 AM
Hi glenngv

yeah sorry for posting to the wrong place. Anyway, I don't seams to see where the entered phone number is compared with the record set phone number variable, 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

glenngv
03-27-2003, 09:19 AM
why this???

username = TRIM( Request.Form( "username" ) )
...
RS.Open "select * from globe where phonenum = '" &username& "'", Con

obviously, the variable username does not correspond to phone number unless you name your phone text field like that.

Abd
03-27-2003, 10:19 AM
Yes I did, I name the phone text filed username

Abd

glenngv
03-28-2003, 01:14 AM
Then just do what I told you in my first post.

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

if RS.EOF then 'it means no record was retrieved

response.write"<script language=""javascript"">" & VbCrLf
response.write"alert('Entered phone number does not exist!');" & VbCrLf
response.write"</script>" & VbCrLf

else

'display info

end if

Abd
03-28-2003, 08:07 AM
Hi glenngv,

thanks alot, it worked, sorry for troubling you this much.

Abd

whammy
03-29-2003, 12:32 AM
P.S. Glenn has a very good point - you shouldn't name a "Phone Number" variable "Username" - EVER!

6 months down the road, if you have to add functionality to your application (not like that ever happens... lol), you won't have a clue what's going on.

Not to mention if another developer is called upon to update your application - he (or she) would most likely tell your boss "This guy is killing me - what was he thinking?" - which falls under the category of "CYA" - but I won't give an explanation of that here. ;)

You should always use the most descriptive variable names you can. This also applies to functions and subroutines... (and classes, etc. when you get into OOP).

Not only for other developers' benefit, but your own...