Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2004, 07:33 PM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default I cannot display an error message

Hi, I would like to display an error message when the user name was already in use. I think this
if (document.frmUser.Username.value.toUpperCase() == "1BM1BM") {
        alert("Username already in use");
        return false; code doesn't work.

The database is user.mdb and the following code enters user's details into users.mdb and the username is the primary key the code is as follow:

<BASEFONT FACE="Comic Sans MS" COLOR="DarkBlue">
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
  function VerifyData()
  {
// if (document.frmUser.Username.value == "" || document.frmUser.Password.value == "" ||
// document.frmUser.FirstName.value == "") {
// alert( "FirstName, Username or Password should not be blank" );
// return false;
// }
    if (document.frmUser.Username.value.toUpperCase() == "1BM1BM") {
        alert("Username already in use");
        return false;
    }
    if (document.frmUser.EMailAddress.value == "" ||
        document.frmUser.EMailAddress.value.indexOf ('@', 0) == -1) {
        alert("Enter a valid email address")
        document.frmUser.EMailAddress.focus()
        return false;
    }
    if (document.frmUser.Password.value != document.frmUser.VerifyPassword.value) {
        alert("Your passwords do not match - please reenter");
        document.frmUser.Password.focus()
        return false;
    }
    if (document.frmUser.Username.value.length < 5) {
        alert("Username must be at least 5 characters")
        document.frmUser.Username.focus()
        return false;
    }
    if (document.frmUser.Password.value.length < 5) {
        alert("Password must be at least 5 characters")
        document.frmUser.Password.focus()
        return false;
    }
      for (i=0; i<document.frmUser.length; i++)
        if (document.frmUser.elements[i].value == "" ||
            document.frmUser.elements[i].value == "Invalid") {
        // prompt("***Not all fields are entered***","You must enter all fields")
            alert("Not all fields are entered")
            document.frmUser.elements[i].focus()
            return false;
        }
    return true;
  }
-->
</SCRIPT>

<TITLE>Register.asp: User Registration</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<CENTER>

</CENTER>
<TABLE BORDER=0 WIDTH=100% BGCOLOR="e8f8f8">
  <TR ALIGN=CENTER>
  <TD><CENTER><H1>New User Registration</H1></CENTER></TD>
  </TR>
</TABLE>

<CENTER>(If you're already registered with us, then click the 'Login' link below.)</CENTER><P>You only need to register with our system if you want to use the personalised digital library. <BR> In order to use these services, please take a few minutes to complete the form below. Once you have done that, you will have full access to the system.




<FORM ACTION="AddUser.asp" NAME="frmUser" METHOD="POST"
              onSubmit="return VerifyData()">
  <TABLE BORDER=0 Width= 100% BGCOLOR="LightBlue">
    <TR>
      <TD WIDTH=20% ROWSPAN=11>&nbsp;</TD>
      <TD>First Name:</TD>
      <TD><INPUT TYPE="Text" NAME="FirstName" VALUE="<%= Session("FirstName") %>"
       SIZE="40"></TD>
    </TR>
    <TR>
      <TD>Last Name:</TD>
      <TD><INPUT TYPE="Text" NAME="Surname" VALUE="<%= Session("Surname") %>"
           SIZE="40"></TD>
    </TR>
    <TR>
      <TD>Address:</TD>
      <TD><INPUT TYPE="Text" NAME="Address1" VALUE="<%= Session("Address1") %>"
           SIZE="40"></TD>
    </TR>
    <TR>
      <TD></TD>
      <TD><INPUT TYPE="Text" NAME="Address2" VALUE= "<%= Session("Address2") %>"
           SIZE="40"> </TD>
    </TR>
    <TR>
      <TD>City:</TD>
      <TD><INPUT TYPE="Text" NAME="City" VALUE= "<%= Session("City") %>"
           SIZE="40"> </TD>
    <TR>
      <TD>Post Code:</TD>
      <TD><INPUT TYPE="Text" NAME="PostCode" VALUE="<%= Session("PostCode") %>"
           SIZE="40"></TD>
    </TR>
    <TR>
      <TD>Country:</TD>
      <TD><INPUT TYPE="Text" NAME="Country" VALUE="<%= Session("Country") %>"
           SIZE="40"></TD>
    </TR>
    <TR>
      <TD>E-Mail Address:</TD>
      <TD><INPUT TYPE="Text" NAME="EMailAddress" VALUE="<%= Session("EMailAddress") %>"
           SIZE="40"></TD>
    </TR>
     <TR>
      <TD>User Name:</TD>
      <TD><INPUT TYPE="Text" NAME="Username" VALUE="<%= Session("Username") %>"
           SIZE="40"></TD>
    </TR>
   <TR>
      <TD>&nbsp;<P>Password:</TD>
      <TD VALIGN=bottom><INPUT TYPE="Password" NAME="Password" VALUE="<%= Session("Password") %>" SIZE="40"></TD>
    </TR>
    <TR>
      <TD>Verify Password:</TD>
      <TD><INPUT TYPE="Password" NAME="VerifyPassword" VALUE=""
       SIZE="40"></TD>
    </TR>
    <TR>
      <TD></TD>
      <TD ALIGN=CENTER COLSPAN=2><BR>
          <INPUT TYPE="Submit" VALUE="Submit Registration">
              &nbsp;&nbsp;<INPUT TYPE="RESET"></TD>
    </TR>
  </TABLE>
</FORM>


<TABLE BORDER=0 WIDTH=100% BGCOLOR="#e8f8f8">
  <TR ALIGN=CENTER>
    <TD WIDTH=33%>Registration</TD>
    <TD WIDTH=33%><A HREF="Login.asp">Login </A></TD>
    <TD WIDTH=33%><A HREF="Browse.asp">Browse Libary </A></TD
  </TR>
</TABLE>

</BODY>
</HTML>


 
Old April 7th, 2004, 02:12 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Can you define "does not work"? AFAICS, the code should check the user name just fine.

However, be aware that the JavaScript validation function VerifyData runs at the client, while your database is located at the server. Using client side validation for something like a duplicate user name is bad practice. It would be too easy to circumvent the JavaScript, submit the form to the server and insert the name....

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display message box in query? tsuersrb Excel VBA 0 February 7th, 2008 02:17 AM
Display Message In ASP.NET mistry_bhavin General .NET 2 February 26th, 2005 04:50 AM
How to display a Message Box creative_eye General .NET 8 February 17th, 2005 07:23 PM
Display message between post to asp wlangel Classic ASP Basics 1 September 8th, 2003 04:34 PM
Message display rodmcleay Forum and Wrox.com Feedback 1 June 5th, 2003 06:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.