user010
Token Flipper
LEVEL 1
300 XP
In this tutorial, we are going to learn on how to create MD5 Registration using PDO in PHP. This simple project helps you to create registration with an MD5 function to encrypt the password field. The feature of this simple project is to save all the data from the field then the password will be encrypted it’s because of the MD5 function that we set in the PDO query.
We construct simple registration form.
And, we have to create the query to insert data into the database using PDO in PHP. Copy and paste to your editor and save it as "insert-query.php".
Those variables below, used this to get the information from the form field given by the user to register a new record of data. As you can see, it has MD5 code in the password and re-type password. The purpose of this is to encrypt the password, so that, in the database the password would be encrypted.
We create a simple trapper, like, we have password and re-type password. If the user type their desired password but the re-type password field does not match in the password field, this simple trapper will give an alert message to the user that their information is incorrect.
PHP query below, this source code used to insert new record of data in the database. Using INSERT Statement. After that, if the data was inserted to the database, the query give an alert message to the user that their data inserted was successful.
This is the full source code for PHP query.
Database Name: db_md5
Here's the output.
This tutorial suit for the beginners who really want to know how to construct PHP query using PDO and to insert data into the database. If you have a question in this tutorial, don't hesitate to leave a comment below. Thank you.
Download
We construct simple registration form.
- <div
style
=
"width:50%;"
>
- <form
method
=
"POST"
action
=
"insert-query.php"
>
- <div
>
- <label
>
First Name</
label
>
- <input
type
=
"text"
name
=
"first_name"
placeholder=
"First Name . . . . ."
required>
- </
div
>
- <div
>
- <label
>
Last Name</
label
>
- <input
type
=
"text"
name
=
"last_name"
placeholder=
"Last Name . . . . ."
>
- </
div
>
- <div
>
- <label
>
Email Address</
label
>
- <input
type
=
"email"
name
=
"email"
placeholder=
"Email Address . . . . ."
required>
- </
div
>
- <div
>
- <label
>
Password</
label
>
- <input
type
=
"password"
name
=
"password"
placeholder=
"Password . . . . ."
required>
- </
div
>
- <div
>
- <label
>
Re-type Password</
label
>
- <input
type
=
"password"
name
=
"re_password"
placeholder=
"Re-type Password . . . . ."
required>
- </
div
>
- <button
type
=
"submit"
name
=
"btn_submit"
>
Submit</
button
>
- </
form
>
- </
div
>
And, we have to create the query to insert data into the database using PDO in PHP. Copy and paste to your editor and save it as "insert-query.php".
Those variables below, used this to get the information from the form field given by the user to register a new record of data. As you can see, it has MD5 code in the password and re-type password. The purpose of this is to encrypt the password, so that, in the database the password would be encrypted.
- <?php
- $first_name
=
$_POST
[
'first_name'
]
;
- $last_name
=
$_POST
[
'last_name'
]
;
- $email
=
$_POST
[
'email'
]
;
- $password
=
md5
(
$_POST
[
'password'
]
)
;
- $re_password
=
md5
(
$_POST
[
're_password'
]
)
;
- ?>
We create a simple trapper, like, we have password and re-type password. If the user type their desired password but the re-type password field does not match in the password field, this simple trapper will give an alert message to the user that their information is incorrect.
- <?php
- if
(
$password
!=
$re_password
)
- {
- echo
"<script>alert('Your Password does not match . . .'); window.location = 'index.php' </script>"
;
- }
- ?>
PHP query below, this source code used to insert new record of data in the database. Using INSERT Statement. After that, if the data was inserted to the database, the query give an alert message to the user that their data inserted was successful.
- <?php
- $database
->
setAttribute
(
PDO::
ATTR_ERRMODE
,
PDO::
ERRMODE_EXCEPTION
)
;
- $insert_query
=
"INSERT INTO tbl_user (first_name, last_name, email, password, re_password)
- VALUES (?, ?, ?, ?, ?)"
;
- $insert
=
$database
->
prepare
(
$insert_query
)
;
- $insert
->
execute
(
array
(
- $first_name
,
- $last_name
,
- $email
,
- $password
,
- $re_password
- )
)
;
- echo
"<script>alert('Account successfully added!'); window.location='index.php'</script>"
;
- ?>
This is the full source code for PHP query.
- <?php
- require_once
(
'database.php'
)
;
- if
(
isset
(
$_POST
[
'btn_submit'
]
)
)
- {
- $first_name
=
$_POST
[
'first_name'
]
;
- $last_name
=
$_POST
[
'last_name'
]
;
- $email
=
$_POST
[
'email'
]
;
- $password
=
md5
(
$_POST
[
'password'
]
)
;
- $re_password
=
md5
(
$_POST
[
're_password'
]
)
;
- if
(
$password
!=
$re_password
)
- {
- echo
"<script>alert('Your Password does not match . . .'); window.location = 'index.php' </script>"
;
- }
- else
- {
- $database
->
setAttribute
(
PDO::
ATTR_ERRMODE
,
PDO::
ERRMODE_EXCEPTION
)
;
- $insert_query
=
"INSERT INTO tbl_user (first_name, last_name, email, password, re_password)
- VALUES (?, ?, ?, ?, ?)"
;
- $insert
=
$database
->
prepare
(
$insert_query
)
;
- $insert
->
execute
(
array
(
- $first_name
,
- $last_name
,
- $email
,
- $password
,
- $re_password
- )
)
;
- echo
"<script>alert('Account successfully added!'); window.location='index.php'</script>"
;
- }
- }
- ?>
Database Name: db_md5
Here's the output.

This tutorial suit for the beginners who really want to know how to construct PHP query using PDO and to insert data into the database. If you have a question in this tutorial, don't hesitate to leave a comment below. Thank you.
Download
You must upgrade your account or reply in the thread to view hidden text.