p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_databases thread: MSG BOX error & guide me


Message #1 by thomasbiju@e... on Mon, 17 Jun 2002 02:54:38
I am a VB programmer trying to study ASP.  Now I am in the process of  
creating a ASP form to Register a New user. My Idea is user have to enter 
email id, username , password and presses the save button. Now My program 
have to check whether the user is already exists or not in the database. 
If it is not existing already program have to set vaddmoddelflg="Add".  If 
it is existing, the program should ask whether you want delete the user or 
modify user details and set  the vaddmoddelflg appropriately("Del" 
or "Mod"). Then ask for the old password. if the password is wrong 
vaddmoddelflg is set to ="Cancel". 

After this my program have to check whether all required fields have to be 
entered or not. If not, program will give appropriate messages.  

Now if all entries are correct, My program have to 
insert/update/Delete/Cancel  the details as per the values of 
vaddmoddelflg.

While executing the code, I got the following error. can any one suggest
the solution for this. 

Error Type:
Microsoft VBScript runtime (0x800A0046)
Permission denied: 'MsgBox'
/HML/NewUser.Asp, line 14


One more question is, Is this the right logic to implement things  like 
this in ASP or is there any other better way ? 



<%@ Language=VBScript %>
<Form method=post  >
     
<%if not isempty(Request.Form("Save") )then%>
   <%
     VAddModDelFlg="Add"
   
     set conn = server.createobject ("adodb.connection")
     conn.open "Provider=SqlOledb;Database=HmlIntranet;uid=biju;pwd=;"
     SqlStr="Select usr_passwd from Users where usr_email='"  & trim
(Request.Form("emailid"))+trim(Request.Form("select1")) & "'"
     Set RSUser = conn.Execute(SqlStr)
     if not RSUser.Eof then
        If MsgBox("User Already Exists. Delete user 
Details ? ",vbYesNo,"Confirm User Action")=vbYes then
           VAddModDelFlg="Del"
        else   
           VAddModDelFlg="Mod"
        end if
        If VAddModDelFlg="Del" or VAddModDelFlg="Mod" then       
           vPassWord=InputBox("Old Password ? ","Password Confirm")
           if vPassWord<>RsUser("usr_passwd") then
	      VAddModDelFlg="Cancel"
	   end if
        end if	  
     end if 	
     vErrFlg="No"
    %>
    <%if isempty(Request.Form("emailid")) or Request.Form("emailid")="" 
THEN%>
         <script>window.alert("Email ID Cannot be Empty")
         </script>
         <%vErrFlg="Yes" %>
    <%end if%>

    <%if instr(Request.Form("emailid"),"@")>0 THEN%>
         <script>window.alert("Error in Email ID ")</script>
         <%vErrFlg="Yes" %>
    <%end if%>

     <%if Request.Form("password1")<>Request.Form("password2") THEN%>
          <script>window.alert("Both the Password should be the same. ")
</script>
          <%vErrFlg="Yes" %>
          
     <%end if%>
      
    <%IF  vErrFlg="No" THEN 
		set conn = server.createobject ("adodb.connection")
	
	conn.open "Provider=SqlOledb;Database=HmlIntranet;uid=biju;pwd=;"


		If VAddModDelFlgM<>"Cancel" then
		   if VAddModDelFlg="Mod" then
 		      SqlStr="Update Users set usr_name='" & Request.Form
("usrname") & "' , usr_passwd='"  & Request.Form("password1") & "' where 
usr_email='" & trim(Request.Form("emailid"))+trim(Request.Form("select1")) 
& "'"
 		   elseif VAddModDelFlg="Del" then
 		      SqlStr="Delete Users where usr_email='" & trim
(Request.Form("emailid"))+trim(Request.Form("select1")) & "'"
		   elseif VAddModDelFlg="Add" then
		      SqlStr="Insert into Users 
(usr_name,usr_email,usr_passwd) values ('" & Request.Form("usrname") 
& "' , '" & trim(Request.Form("emailid"))+trim(Request.Form("select1")) 
& "' , '" & Request.Form("password1") & "' )"
		   end if	
		   Set RSUser = conn.Execute(SqlStr)
		end if	

	    'if not RSUser.Eof then
		'	session("usrname")=Request.Form("usrname")
		'end if 	
		vEmailId=" "
		vUsrName=" "
		vPassword1=" "
		vPassword2=" "
	else	
		
		vEmailId=Request.Form("emailid")
		vUsrName=Request.Form("usrname")
		vPassword1=Request.Form("password1")
		vPassword2=Request.Form("password2")
    END IF 
    %>
   

<%end if%>

<HTML>


<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<P>&nbsp;</P>
<TABLE WIDTH="75%" ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1 
style="HEIGHT: 175px; WIDTH: 294px">
	<TR><TD align=middle colSpan=5>User Details(Fields with 
      *&nbsp; must be filled.)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR>
	<TR>
		<TD>*</TD>
		<TD>Email Id</TD>
		<TD><INPUT id=emailid name=emailid  value="<%Response.write
(vemailid)%>"
      style="HEIGHT: 23px; WIDTH: 111px"></TD>
		<TD><SELECT id=select1 
      name=select1 style="HEIGHT: 22px; LEFT: 1px; TOP: 3px; WIDTH: 191px" 
     > <OPTION value="@harrisonsmalayalam.com"
        
        selected>@harrisonsmalayalam.com</OPTION></SELECT></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD>*</TD>
		<TD>User Name</TD>
		<TD><INPUT id=usrname name=usrname value="<%Response.Write
(vusrname)%>"
      style="HEIGHT: 22px; LEFT: 1px; TOP: 2px; WIDTH: 111px" 
     ></TD>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD>*</TD>
		<TD>Password</TD>
		<TD><INPUT id=password1 name=password1 
    type=password style="HEIGHT: 22px; WIDTH: 113px"></TD>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD>*</TD>
		<TD>Confirm Password</TD>
		<TD><INPUT id=password2 name=password2 
    type=password style="HEIGHT: 22px; WIDTH: 113px"></TD>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>		<TD></TD>
		<TD></TD>
		<TD><INPUT id=Save name=Save type=submit value=Save><INPUT 
id=Cancel name=Cancel type=reset value=Cancel></TD>
		<TD></TD>
</TR>
</TABLE>
</BODY>
</HTML>

</Form>
Message #2 by "=?iso-8859-1?B?QUpBWK4=?=" <ajax@i...> on Mon, 17 Jun 2002 10:37:14 +0530
hi,

The msgbox funtion is not available for server side vbscripting. The error
is normal behaviour. because the msgbox pops up on the server and halts
execution for user input finally resulting in a timeout and that error on
the client-side.

What u need to do is use the response.redirect and direct the user to
different pages where u can include appropriate messages and forms to
collect user data.

Its is imperative that something like a user registration form shld follow
certain basic rules for maintaining uniqueness. Another option u might want
to check out is Remote scripting, This will check for uniqueness on the
on_blur event of the text box for userid (similar to lost focus event in
VB). However it uses a Java Applet and therefore maynot work on certain
machines that do not have the JVM installed. However if workable can save
the end user a lot of irritation.

Ideally i would suggest a mix-n-match of both approaches. Remotescripting
maybe optional, but server side validation of posted data-- absolutely
necessary..


hth
ajax®







----- Original Message -----
From: <thomasbiju@e...>
To: "ASP Databases" <asp_databases@p...>
Sent: Monday, June 17, 2002 2:54 AM
Subject: [asp_databases] MSG BOX error & guide me


> I am a VB programmer trying to study ASP.  Now I am in the process of
> creating a ASP form to Register a New user. My Idea is user have to enter
> email id, username , password and presses the save button. Now My program
> have to check whether the user is already exists or not in the database.
> If it is not existing already program have to set vaddmoddelflg="Add".  If
> it is existing, the program should ask whether you want delete the user or
> modify user details and set  the vaddmoddelflg appropriately("Del"
> or "Mod"). Then ask for the old password. if the password is wrong
> vaddmoddelflg is set to ="Cancel".
>
> After this my program have to check whether all required fields have to be
> entered or not. If not, program will give appropriate messages.
>
> Now if all entries are correct, My program have to
> insert/update/Delete/Cancel  the details as per the values of
> vaddmoddelflg.
>
> While executing the code, I got the following error. can any one suggest
> the solution for this.
>
> Error Type:
> Microsoft VBScript runtime (0x800A0046)
> Permission denied: 'MsgBox'
> /HML/NewUser.Asp, line 14
>
>
> One more question is, Is this the right logic to implement things  like
> this in ASP or is there any other better way ?
>
>
>
> <%@ Language=VBScript %>
> <Form method=post  >
>
> <%if not isempty(Request.Form("Save") )then%>
>    <%
>      VAddModDelFlg="Add"
>
>      set conn = server.createobject ("adodb.connection")
>      conn.open "Provider=SqlOledb;Database=HmlIntranet;uid=biju;pwd=;"
>      SqlStr="Select usr_passwd from Users where usr_email='"  & trim
> (Request.Form("emailid"))+trim(Request.Form("select1")) & "'"
>      Set RSUser = conn.Execute(SqlStr)
>      if not RSUser.Eof then
>         If MsgBox("User Already Exists. Delete user
> Details ? ",vbYesNo,"Confirm User Action")=vbYes then
>            VAddModDelFlg="Del"
>         else
>            VAddModDelFlg="Mod"
>         end if
>         If VAddModDelFlg="Del" or VAddModDelFlg="Mod" then
>            vPassWord=InputBox("Old Password ? ","Password Confirm")
>            if vPassWord<>RsUser("usr_passwd") then
>       VAddModDelFlg="Cancel"
>    end if
>         end if
>      end if
>      vErrFlg="No"
>     %>
>     <%if isempty(Request.Form("emailid")) or Request.Form("emailid")=""
> THEN%>
>          <script>window.alert("Email ID Cannot be Empty")
>          </script>
>          <%vErrFlg="Yes" %>
>     <%end if%>
>
>     <%if instr(Request.Form("emailid"),"@")>0 THEN%>
>          <script>window.alert("Error in Email ID ")</script>
>          <%vErrFlg="Yes" %>
>     <%end if%>
>
>      <%if Request.Form("password1")<>Request.Form("password2") THEN%>
>           <script>window.alert("Both the Password should be the same. ")
> </script>
>           <%vErrFlg="Yes" %>
>
>      <%end if%>
>
>     <%IF  vErrFlg="No" THEN
> set conn = server.createobject ("adodb.connection")
>
> conn.open "Provider=SqlOledb;Database=HmlIntranet;uid=biju;pwd=;"
>
>
> If VAddModDelFlgM<>"Cancel" then
>    if VAddModDelFlg="Mod" then
>         SqlStr="Update Users set usr_name='" & Request.Form
> ("usrname") & "' , usr_passwd='"  & Request.Form("password1") & "' where
> usr_email='" & trim(Request.Form("emailid"))+trim(Request.Form("select1"))
> & "'"
>      elseif VAddModDelFlg="Del" then
>         SqlStr="Delete Users where usr_email='" & trim
> (Request.Form("emailid"))+trim(Request.Form("select1")) & "'"
>    elseif VAddModDelFlg="Add" then
>       SqlStr="Insert into Users
> (usr_name,usr_email,usr_passwd) values ('" & Request.Form("usrname")
> & "' , '" & trim(Request.Form("emailid"))+trim(Request.Form("select1"))
> & "' , '" & Request.Form("password1") & "' )"
>    end if
>    Set RSUser = conn.Execute(SqlStr)
> end if
>
>     'if not RSUser.Eof then
> ' session("usrname")=Request.Form("usrname")
> 'end if
> vEmailId=" "
> vUsrName=" "
> vPassword1=" "
> vPassword2=" "
> else
>
> vEmailId=Request.Form("emailid")
> vUsrName=Request.Form("usrname")
> vPassword1=Request.Form("password1")
> vPassword2=Request.Form("password2")
>     END IF
>     %>
>
>
> <%end if%>
>
> <HTML>
>
>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
> </HEAD>
> <BODY>
>
> <P>&nbsp;</P>
> <TABLE WIDTH="75%" ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1
> style="HEIGHT: 175px; WIDTH: 294px">
> <TR><TD align=middle colSpan=5>User Details(Fields with
>       *&nbsp; must be filled.)
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR>
> <TR>
> <TD>*</TD>
> <TD>Email Id</TD>
> <TD><INPUT id=emailid name=emailid  value="<%Response.write
> (vemailid)%>"
>       style="HEIGHT: 23px; WIDTH: 111px"></TD>
> <TD><SELECT id=select1
>       name=select1 style="HEIGHT: 22px; LEFT: 1px; TOP: 3px; WIDTH: 191px"
>      > <OPTION value="@harrisonsmalayalam.com"
>
>         selected>@harrisonsmalayalam.com</OPTION></SELECT></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD>*</TD>
> <TD>User Name</TD>
> <TD><INPUT id=usrname name=usrname value="<%Response.Write
> (vusrname)%>"
>       style="HEIGHT: 22px; LEFT: 1px; TOP: 2px; WIDTH: 111px"
>      ></TD>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD>*</TD>
> <TD>Password</TD>
> <TD><INPUT id=password1 name=password1
>     type=password style="HEIGHT: 22px; WIDTH: 113px"></TD>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR>
> <TD>*</TD>
> <TD>Confirm Password</TD>
> <TD><INPUT id=password2 name=password2
>     type=password style="HEIGHT: 22px; WIDTH: 113px"></TD>
> <TD></TD>
> <TD></TD>
> </TR>
> <TR> <TD></TD>
> <TD></TD>
> <TD><INPUT id=Save name=Save type=submit value=Save><INPUT
> id=Cancel name=Cancel type=reset value=Cancel></TD>
> <TD></TD>
> </TR>
> </TABLE>
> </BODY>
> </HTML>
>
> </Form>

Message #3 by "Ken Schaefer" <ken@a...> on Mon, 17 Jun 2002 13:53:27 +1000
You can't "pop-up" a message box in server-side script, because it'll pop-up
on the server, but the user context that the script is running in does not
have interactive priveleges.

You need to use "client-side" script to pop-up a message box. For
cross-browse purposes you should use the javascript alert() function for
this.

Also, anything you send to the client to be rendered, must be after the
<html> tag.
Secondly, the result of a client selecting an option in a dialogue box is
not visible to the server. Only values that have been "posted" to the server
(eg from a form), or passed via the URL, or passed via a cookie are visible
(in the Request.Form() and Request.Querystring() collection)

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <thomasbiju@e...>
Subject: [asp_databases] MSG BOX error & guide me


: I am a VB programmer trying to study ASP.  Now I am in the process of
: creating a ASP form to Register a New user. My Idea is user have to enter
: email id, username , password and presses the save button. Now My program
: have to check whether the user is already exists or not in the database.
: If it is not existing already program have to set vaddmoddelflg="Add".  If
: it is existing, the program should ask whether you want delete the user or
: modify user details and set  the vaddmoddelflg appropriately("Del"
: or "Mod"). Then ask for the old password. if the password is wrong
: vaddmoddelflg is set to ="Cancel".
:
: After this my program have to check whether all required fields have to be
: entered or not. If not, program will give appropriate messages.
:
: Now if all entries are correct, My program have to
: insert/update/Delete/Cancel  the details as per the values of
: vaddmoddelflg.
:
: While executing the code, I got the following error. can any one suggest
: the solution for this.
:
: Error Type:
: Microsoft VBScript runtime (0x800A0046)
: Permission denied: 'MsgBox'
: /HML/NewUser.Asp, line 14
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index