How to check if username already exists using web services

If you want to learn how to use and benefit from the AJAX Web Service feature, please consider this situation:

You developed a site (completely or partly with MX AJAX Toolbox). Your site visitors should create an account on the site before being able to use it. For creating this account, they are redirected to a page where a registration form is displayed. The information they enter in that form (name, username, password) is stored in a database. Of course, the username must have unique values. Now if there is a site visitor who wants to register, and it happens that he/she enters a username that is already stored in the database, only after the form is completely filled out and submitted will they learn that the registration failed (because the username already exists).

By using an AJAX web service, you can optimize the registration process like this: the form field that must be checked will be checked right after a value is entered there, and not after submitting the form. This way, site visitors do not have to fill out the whole form (that can be huge sometimes) and find out in the end that it didn't work. Try this yourself by following the instructions below.

Note: The server-side function used in this tutorial is for the PHP server model.

 

First of all, set up the Dreamweaver environment:

  1. The database used in this tutorial has only one table, user_urs, that has four columns: id_usr, name_usr, username_usr, and password_usr (their names are more than suggestive). Create its structure by using the scripts provided in the .zip package (either .sql or .mdb), in the \tutorials\Check username\db folder.

  2. Create a new page in one of your sites (used for testing/learning), in the root, and name it check_username.

  3. Open the check_username file and define a new Dreamweaver database connection: conn_web_service. Configure it to connect to your database server and make it point to the database containing the table described above.

  4. There is another file that you will need: when a duplicate username is typed, the site visitor will be redirected to another page where he/she will be told that the entered username already exists. So create a new file in the site root and name it user_exists. Open it and enter the following text: The entered username already exists! Please enter another value. Save the file and then close it.

Now that the database connection and the files for the registration form and redirect on failure are created, continue with the next steps and learn how to use an AJAX web service:

  1. Open the check_username file, if not already opened.

  2. Click the Insert Record : Record Insertion Form Wizard icon in the Application tab of the Insert bar:


                                  

  3. Configure the Record Insertion Form dialog box that opens as shown below:


                                 

  4. Save, upload, and preview the check_username page in browser. Try it out by creating a new user account and check the database for the new record:


                                

  5. Back in Dreamweaver, apply the Check New Username server behavior from the Application panel, Server Behaviors -> + -> User Authentication. Configure the dialog box that opens as shown below:


                                

  6. Save, upload, and test the page in browser again. Notice that if you enter the same username as the one registered before (sunshine), you will be redirected to the user_exists page:


                               

  7. Back in Dreamweaver, in Design view, click the username text field, press the right arrow key, and then switch to Code view. Right where the cursor is placed (before </td>), paste the following code section: <div id="duplicate_alert" style="color: red;"></div>. You just created a div container for the alert message displayed (in red) when a duplicate username attempts to be created.

  8. To save time for your site visitors that want to register, and to check the form fields that need validation as they are given values, use an AJAX web service. Before that though, create a server-side function in page:

  9. Launch the AJAX Web Service Wizard from the MX AJAX Toolbox tab of the Insert bar. The wizard has two steps.

  10. Configure the first step of the AJAX Web Service Wizard as shown below:


                              

  11. Configure the second step of the AJAX Web Service Wizard as shown below:


                             

  12. Save, upload, and test the page in browser one more time. Notice that if you enter the same username as the one registered before, you will be notified right after filling out that field that the value entered is not valid:

 

This was just an example of how you can benefit from the AJAX web service, but there is much more you can achieve!

seco  ali

t gives me error message says error 5 not a avalid json string 

any help?


thanks in advance.