Form Registrasi Anggota dengan Validasi Email (PHP MySQL: Registration form that will email for registra to validate)

Anda mungkin sering melihat sebuah form registrasi yang begitu Anda melakukan registrasi, Anda akan mendapatkan email notifikasi dan link untuk melakukan validasi terhadap account yang baru Anda buat. Tutorial ini sangat mudah untuk diikuti.

Lihat sumber artikel asli:

Note: Form di dalam tutorial ini tidak dilengkapi dengan filter. Anda dapat menambahkannya sendiri.


i have a good registration system with login (dw cs4 David’s book), but would like to expand or add to it. The user enter all info in registration form, including email, and then an email is sent to user for validation before they can log in.


This question actually is from RJWeb. In this solution, we will use these files: 1. Register.php, a page where the registration form is displayed 2. Register_ok.php, this page will send an email as notification to registrant to activate their account. 3. Register_error.php, notification page if the registration process failed 4. Activate.php, a page contain link for activation 5. Admin.php, admin page. Only can be accessed by admin/member who has access level 1.

Detailed explanation

This recipe request actually is from RJWeb, one of the Adobe Cookbook user.

Source code:  adobe_cookbooks_start.rar and adobe_cookbooks_end.rar

A MySQL table called admin:
01         CREATE TABLE IF NOT EXISTS `admin` (
02   `id` int(10) NOT NULL AUTO_INCREMENT,
03   `name` varchar(64) NOT NULL,
04   `email` varchar(64) NOT NULL,
05   `username` varchar(64) NOT NULL,
06   `password` varchar(64) NOT NULL,
07   `activation` varchar(64) NOT NULL,
08   `level` int(2) NOT NULL DEFAULT '0',
10   PRIMARY KEY (`id`)
13 --
14 -- Dumping data untuk tabel `admin`
15 --
17 INSERT INTO `admin` (`id`, `name`, `email`, `username`, `password`, `activation`, `level`, `date_registered`) VALUES
18 (1, 'Andoyo', '', 'andoyo', 'andoyo', '8e67d638c0d130a4d66b2888ffc8335b', 0, '2011-09-21 10:32:16');
The level column of this table is set zero (0). The admin/member who has 0 access level wil can not access admin page (admin.php).
  1. Firstly, download the source code above and extract all of them to your web/site root.
  2. Upload/export the MySQL table.
  3. Make your site definiton (Site Setup)
  4. Make your database connection. In this case a database connection file was made, called: adobe_cookbooks.php,

Registration page: register.php

  1. Open file: register.php. We will build a registration form under the text “Registration page”.
  2. Click Insert > Data Objects > Insert Record > Record Insertion Form Wizard . The window Insertion form wizard will come out (Figure 1).
  3. Connection: adobe_cookbooks
  4. Table: admin
  5. After inserting, go to: register_ok.php. You can click Browse to find the file: register_ok.php.
  6. In the Form Fields menu, you can see there Plus sign (+) for Add item and Minus sign (-) for Remove item. At the bottom of that signs there are some columns that we want to insert in.
  7. Remove the id item by clicking id column, then click Minus sign (-). The id column will be generated automatically by MySQL.
  8. Do the same for the date_registered  and level column. Remove both of the columns. The date_registered is set automatically by MySQL and level is set zero (0) value as a default.
  9. Click username column.
  10. Display as: Password field
  11. Click activation column.
  12. Display as: hidden field . The activation column will be set as a hidden value. The value will be same as username column but encrypted using MD5 (or SHA1).
  13. Click OK to finish it.
  14. Save your file

Ammend the code in register.php

In the Code View, find this code:


1       if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
2 $insertSQL = sprintf("INSERT INTO `admin` (name, email, username, password, activation) VALUES (%s, %s, %s, %s, %s)",
3                      GetSQLValueString($_POST['name'], "text"),
4                      GetSQLValueString($_POST['email'], "text"),
5                      GetSQLValueString($_POST['username'], "text"),
6                      GetSQLValueString($_POST['password'], "text"),
7                      GetSQLValueString($_POST['activation'], "text"));


We will add a new variable called $my_activation, where the value is same as $_POST[‘username’] encrypted using MD5. The changing of the code will be like this:


01         if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
02 <strong>$my_activation= md5($_POST['username']);</strong>
03   $insertSQL = sprintf("INSERT INTO `admin` (name, email, username, password, activation) VALUES (%s, %s, %s, %s, %s)",
04                        GetSQLValueString($_POST['name'], "text"),
05                        GetSQLValueString($_POST['email'], "text"),
06                        GetSQLValueString($_POST['username'], "text"),
07                        GetSQLValueString($_POST['password'], "text"),
09 <strong>GetSQLValueString($my_activation, "text"));</strong>


Save your register.php file and try it through your browser.


Sending a notification email: register_ok.php

After a visitor fill all of the information through the form and click Insert record, he/she will be redirected to register_ok.php page. An email script will send the activation link to the email.

  1. Open file: register_ok.php
  2. Click Insert > Data Objects > Recordset . The Recordset window will come out.
  3. Name: rsOK
  4. Connection: adobe_cookbooks
  5. Table: admin
  6. Column: All
  7. Sort: id , and Descending
  8. Click Advanced, ammend this code:  SELECT *
    1                 FROM `admin`
    2 ORDER BY id DESC
  9. Type LIMIT 1 after ORDER BY id DESC. The new code will be like this:  SELECT *
    1                 FROM `admin`
  10. Klik OK
  11. Save your file

Add PHP Mail function in your code:

After this PHP Code:


1         mysql_select_db($database_adobe_cookbooks, $adobe_cookbooks);
2 $query_rsOK = "SELECT * FROM `admin` ORDER BY id DESC LIMIT 1";
3 $rsOK = mysql_query($query_rsOK, $adobe_cookbooks) or die(mysql_error());
4 $row_rsOK = mysql_fetch_assoc($rsOK);
5 $totalRows_rsOK = mysql_num_rows($rsOK);
Press enter to make some spaces, and then add the following code:
01                 $my_activation = $row_rsOK['activation'];
02 $to = $row_rsOK['email'];
03 $subject = "Hi ".$row_rsOK['name'];
04 $body = "<html><body>" .
05 "<h2>Thank you for your registration.</h2>" .
06 "<p>To active your account, please visit this link</p>".
08 "From: Webmaster";
09 $headers "From: Webmaster Java Web Media <>\r\n" .
10 "MIME-Version: 1.0\r\n" .
11 "Content-type: text/html; charset=UTF-8";
13 if (!mail($to, $subject, $body, $headers)) {
14 $redirect= "register_error.php";
15   header( "Location: ".$redirect ) ;
16  }
So the code will be like this:
01                 mysql_select_db($database_adobe_cookbooks, $adobe_cookbooks);
02 $query_rsOK = "SELECT * FROM `admin` ORDER BY id DESC LIMIT 1";
03 $rsOK = mysql_query($query_rsOK, $adobe_cookbooks) or die(mysql_error());
04 $row_rsOK = mysql_fetch_assoc($rsOK);
05 $totalRows_rsOK = mysql_num_rows($rsOK);
07 $my_activation = $row_rsOK['activation'];
08 $to = $row_rsOK['email'];
09 $subject = "Hi ".$row_rsOK['name'];
10 $body = "<html><body>" .
11 "<h2>Thank you for your registration.</h2>" .
12 "<p>To active your account, please visit this link</p>".
14 "From: Webmaster";
15 $headers "From: Webmaster Java Web Media <>\r\n" .
16 "MIME-Version: 1.0\r\n" .
17 "Content-type: text/html; charset=UTF-8";
19 if (!mail($to, $subject, $body, $headers)) {
20 $redirect= "register_error.php";
21   header( "Location: ".$redirect ) ;
22  }
I add some variable in that code, they are:
  1. $my_activation, as a random string generated using MD5 has to make a link
  2. $to, as an email address owned by the last registrant.
  3. $redirect, as a redirection page if the registration process is failed.

Account activation: activate.php

The next step is activating your account. The member/admin will get an email contain activation link. For example the link could be like this http://localhost/adobe_cookbooks/activate.php?activation=8e67d638c0d130a4d66b2888ffc8335b.

Make a recordset with link parameter:

  1. Open file: activate.php
  2. Open file:  register_ok.php
  3. Click  Insert > Data Objects > Recordset . The Recordset window will come out.
  4. Name: rsActivate
  5. Connection: adobe_cookbooks
  6. Table: admin
  7. Column: All
  8. Filter: activation, URL Parameter, =, activation.
  9. Click OK

Make an update form to activate the account:


  1. Click Insert > Data Objects > Update Record > Record Update Form Wizard . The window will come out.
  2. Connection: adobe_cookbooks
  3. Table to update: admin
  4. Select record from: rsActivate
  5. Unique key column: activation. Uncheck the Numeric option.
  6. After updating, go to: login.php,
  7. In the Form fields: option, do the following action.
  8. Click id column ,
  9. Remove it by clicking the Minus sign (-)
  10. Do the same as step 8-9 to these columns: name,  email, username,  password, activation, and date_registered  . Remove all of them by clicking Minus sign (-)
  11. Click level column
  12. Display as: Hidden field
  13. Default value: 1 , clean this default PHP Code: <?php echo htmlentities($row_rsActivate[‘level’], ENT_COMPAT, ‘utf-8’); ?> and change it into 1.
  14. Click OK
  15. Save your file

Make your form more readable for the visitors:

In code view, see this code:


1           <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
2 <table align="center">
3   <tr valign="baseline">
4     <td nowrap="nowrap" align="right">&nbsp;</td>
5     <td><input type="submit" value="Update record" /></td>
6   </tr>
7 </table>
Ammend that code to be like this:
1                   <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
2 <table align="center">
3   <tr valign="baseline">
4     <td nowrap="nowrap" align="right">Hi <strong><?php echo $row_rsActivate['name']; ?></strong>. Activate your account by clicking Activate button.</td>
5     <td><input type="submit" value="Activate my account" /></td>
6   </tr>
7 </table>
This form change the level column where the value is set zero value (0) and change it into 1 (one) as an access level. After the activation is done, the user will be redirected to the login page (login.php).

Make your login form: login.php

The next step is make your login page.

Make the login form:

  1. Open file: login.php
  2. In Design View, press Enter after the text “Login Page”
  3. Click Insert > Form > Form
  4. Click Insert > Form > Text Field . The window will come out
  5. ID: username
  6. Label: Username:
  7. Click OK.
  8. In Design View, put your cursor after the text field and press Enter
  9. ID: password
  10. Label: Password:
  11. Click OK.
  12. Change this code:  <input type=”text” name=”password” id=”password” /> to be like this: <input type=”password” name=”password” id=”password” />. Thats mean we change the  type=”text” to be type=”password”. After the password field, press Enter.
  13. Click Insert > Form > Button 
  14. ID: Submit, 
  15. Clik OK

Activating login form:

  1. Click Insert > Data Objects > User Authentication > Log In User
  2. Get input from form: form1
  3. Username field: username
  4. Password field: password
  5. Validate using connection: adobe_cookbooks
  6. Table: admin
  7. Username column: username, click pop up menu to choose it
  8. Password column: password
  9. If login succesds, go to: admin.php
  10. Select the option by clicking it: Go to Previous URL (if exist)
  11. If login fails, go to: login.php
  12. Restrict access based on: username, password, and access level.
  13. Get level from: level, click the pop up menu
  14. Click OK
  15. Save your work


Restrict admin page: admin.php

The next step is make sure that admin page only can be accessed after the user logged in.

Protect the page:

  1. Open file: admin.php
  2. Click Insert > Data Objects > User Authentication > Restrict Access To Page
  3. Restrict access based on:   username, password, and access level.
  4. Click Define to make a new access level
  5. Name: 1, type it manually
  6. Click Plus sign (+)
  7. Click OK
  8. Select level(s): 1, make sure you selected 1 .
  9. If access denied, go to: login.php
  10. Click OK
  11. Save your work

Log Out link:

  1. In Design View, select “Log Out” text.
  2. Click Insert > Data Objects > User Authentication > Log Ou User
  3. Log Out When: Link Clicked: Selection: “Log Out”
  4. When done, go to: index.php
  5. Click OK
  6. Save your work.

Source code:  adobe_cookbooks_start.rar and  adobe_cookbooks_end.rar

Java Web Media: Web Design di Kota Depok

Java Web Media adalah perusahaan yang bergerak di bidang web design, web programming, web application, web education, graphic design dan graphic education yang berbasis di kota depok.

36 thoughts to “Form Registrasi Anggota dengan Validasi Email (PHP MySQL: Registration form that will email for registra to validate)”

  1. Unquestionably consider that that you stated. Your favourite justification appeared to be at the net the simplest factor to take into accout of. I say to you, I certainly get irked while people consider worries that they just do not understand about. You managed to hit the nail upon the highest and also outlined out the whole thing without having side-effects , other folks could take a signal. Will likely be back to get more. Thank you

  2. Hey! This post could not be written any better! Reading this post reminds me of
    my previous room mate! He always kept chatting about this.

    I will forward this post to him. Fairly certain he will have a good
    read. Thanks for sharing!

  3. I’m really inspired along with your writing abilities and also with
    the structure to your weblog. Is that this a paid subject or did
    you customize it your self? Anyway stay up the nice quality writing, it’s uncommon to
    see a nice weblog like this one today..

  4. This is a natural occurrence and can be easily mistaken for acne.

    The job of acne skin care products to help normalize shedding into the pore to prevent blockages from occurring, killing the Propionibacterium acnes, and reducing inflammation. Pure genuine pearl powder does not totally
    dissolve in water or liquid, so be sure you stir as you drink.

  5. I see you share interesting things here, you can earn some extra cash, your
    website has big potential, for the monetizing method, just type in google – K2 advices how to monetize a website

  6. It will also increase the ranking of your website on search
    engines and will drive more traffic to your website. It has the
    highest ROI (Return of Invesment) in all advertisement channels.
    There are other ways to improve your ranking in Googlemaps, the
    purpose of this blog post is not to tell you EVERYTHING
    Frederick Web Promotions can do to improve your ranking, the purpose of this particular blog post is to:.

    My blog post Google

  7. Heyy I know this is off topic bbut I was wodering if you knew of any widgets I coud add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe
    yyou would have some experience with something like this.
    Pleaqse leet me know if you run into anything. I truly enjoy reading your blog and I look forward
    to your new updates.

  8. Over-the-Road Transportation, Direct Contract Truck Services,
    Truck Brokerage, Local Drayage, Intermodal Transportation, Direct
    Contract, Railroad Supplied Intermodal Equipment, Third Party
    Supplied Intermodal Equipment, Ocean Container Domestic, LTL
    Transportation, Interstate, Regional, Domestic Air Brokerage
    and Expedited Services are some of the major transport service features of MITCO.
    Now fast forward almost seven years later, the company I started is still
    viable, profitable and growing exponentially; so exciting.
    I’ve been speaking positively about Scentsy so far and you might think that this is like a lot of other company reviews.

  9. Oh my goodness! Awesome article dude! Thanks,
    However I am having troubles with your RSS.
    I don’t now why I cannot subscribe to it. Is there anybody else getting the same RSS
    issues? Anybody who knows the solution will you kindly respond?

  10. Nothing is hotter this season than the classic shirtdress, which is tailored enough
    for work but still exudes a sassy attitude. As much as possible they should have two or more pairs
    in their closets. Patterns are perceived as dull by most people, especially
    men. If you want to mask a tummy, opt for an empire waist style.

  11. Creating ontologies can be supported using different
    techniques and some common tools. SEO company Yule and SEO company Amelia island use the best seo techniques and strategies to get
    their clients’ websites on top of search engine result pages.
    In most cases, there’s no need to use extremely
    fancy graphics, Adobe Flash and other effects.

  12. Hey there! Quick question that’s entirely off topic. Do you know
    how to make your site mobile friendly? My site looks weird when browsing
    from my iphone 4. I’m trying to find a theme or plugin that might be able to
    correct this issue. If you have any suggestions, please share.

  13. Everything is very open with a really clear explanation of
    the challenges. It was truly informative. Your site is very useful.
    Many thanks for sharing!

  14. I was excited to uncover this website. I need to to thank you for ones time for this
    particularly fantastic read!! I definitely savored every little bit
    of it and i also have you saved as a favorite to look at new
    things in your web site.

  15. They have different perception of things and react differently in various situations.
    In the Videos women are executing to satisfy user’s most erotic fantasy.
    MILFs will most like be very protective of their
    children it may be awhile before you meet them.

  16. I do not know if it’s just me or if perhaps everyone
    else experiencing issues with your blog. It looks like some of the written text within your
    posts are running off the screen. Can someone else please provide feedback and let me know if
    this is happening to them as well? This might be a issue with my
    browser because I’ve had this happen previously. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *