{"id":1352,"date":"2022-11-28T09:07:14","date_gmt":"2022-11-28T01:07:14","guid":{"rendered":"https:\/\/hostscripter.com\/?p=1352"},"modified":"2022-11-28T09:07:14","modified_gmt":"2022-11-28T01:07:14","slug":"part-5-create-your-own-registration-system-using-php-and-mysql","status":"publish","type":"post","link":"https:\/\/hostscripter.com\/?p=1352","title":{"rendered":"Part 5: Create your own Registration System using PHP and MySql"},"content":{"rendered":"<h2 id=\"validatingformdata\">5. Validating Form Data<\/h2>\n<p>We already have basic validation in our PHP script but what if we want to check if the email is actually an email or if the username and password should be a certain amount of characters long, you can do that with the codes below, add them in the\u00a0<i class=\"hl\">register.php<\/i>\u00a0file before the following line:<\/p>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token variable\">$stmt<\/span> <span class=\"token operator\">=<\/span> <span class=\"token variable\">$con<\/span><span class=\"token operator\">-<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token function\">prepare<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'SELECT id, password FROM accounts WHERE username = ?'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>Email Validation<\/h3>\n<div class=\"code-header\"><\/div>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span><span class=\"token function\">filter_var<\/span><span class=\"token punctuation\">(<\/span><span class=\"token global\">$_POST<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">'email'<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token constant\">FILTER_VALIDATE_EMAIL<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n\t<span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'Email is not valid!'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>Invalid Characters Validation<\/h3>\n<div class=\"code-header\"><\/div>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">preg_match<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'\/^[a-zA-Z0-9]+$\/'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token global\">$_POST<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">'username'<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">==<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'Username is not valid!'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>Character Length Check<\/h3>\n<div class=\"code-header\"><\/div>\n<pre class=\" language-php\"><code class=\" language-php\"><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token global\">$_POST<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">'password'<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">20<\/span> <span class=\"token operator\">||<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token global\">$_POST<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">'password'<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span>\r\n\t<span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">'Password must be between 5 and 20 characters long!'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<span class=\"token punctuation\">}<\/span><\/code><\/pre>\n<p>You should always implement your own validation, these are just basic examples.<\/p>\n<div data-counters='false' data-style='square' data-size='small' data-url='https:\/\/hostscripter.com\/?p=1352' data-title='Part 5: Create your own Registration System using PHP and MySql' class='linksalpha_container linksalpha_app_3'><a href='\/\/www.linksalpha.com\/share?network='facebook' class='linksalpha_icon_facebook'><\/a><a href='\/\/www.linksalpha.com\/share?network='twitter' class='linksalpha_icon_twitter'><\/a><a href='\/\/www.linksalpha.com\/share?network='googleplus' class='linksalpha_icon_googleplus'><\/a><a href='\/\/www.linksalpha.com\/share?network='mail' class='linksalpha_icon_mail'><\/a><\/div><div data-position='' data-url='https:\/\/hostscripter.com\/?p=1352' data-title='Part 5: Create your own Registration System using PHP and MySql' class='linksalpha_container linksalpha_app_7'><a href='\/\/www.linksalpha.com\/share?network='facebook' class='linksalpha_icon_facebook'><\/a><a href='\/\/www.linksalpha.com\/share?network='twitter' class='linksalpha_icon_twitter'><\/a><a href='\/\/www.linksalpha.com\/share?network='googleplus' class='linksalpha_icon_googleplus'><\/a><a href='\/\/www.linksalpha.com\/share?network='mail' class='linksalpha_icon_mail'><\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>5. Validating Form Data We already have basic validation in our PHP script but what if we want to check if the email is actually an email or if the [&hellip;]<\/p>\n","protected":false},"author":301,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9KaPo-lO","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1349,"url":"https:\/\/hostscripter.com\/?p=1349","url_meta":{"origin":1352,"position":0},"title":"Part 4: Create your own Registration System using PHP and MySql","author":"h05t5cr1pt3r","date":"November 28, 2022","format":false,"excerpt":"4. Registering Users with PHP & MySQL Now we need to create the registration file that will process the form fields, check for basic validation, and insert the new account into our database. The registration page will require a connection to our database and therefore we must include the necessary\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/hostscripter.com\/?cat=4"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1354,"url":"https:\/\/hostscripter.com\/?p=1354","url_meta":{"origin":1352,"position":1},"title":"Part 6: Create your own Registration System using PHP and MySql","author":"h05t5cr1pt3r","date":"November 28, 2022","format":false,"excerpt":"6. Implementing Account Activation The account activation system will send an email to the user with the activation link when the user has registered. The first thing we need to do is to go into\u00a0phpMyAdmin\u00a0and select our database, in our case this would be\u00a0phplogin, you can either add the column\u00a0activation_code\u00a0to\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/hostscripter.com\/?cat=4"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1343,"url":"https:\/\/hostscripter.com\/?p=1343","url_meta":{"origin":1352,"position":2},"title":"Part 1: Create your own Registration System using PHP and MySql","author":"h05t5cr1pt3r","date":"November 28, 2022","format":false,"excerpt":"This tutorial is a follow up to our previous tutorial\u00a0Secure Login System with PHP and MySQL. In this tutorial, we'll be creating a secure registration form and implementing basic validation. A registration form is what your website's visitors can use to register their details, which will subsequently be stored in\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/hostscripter.com\/?cat=4"},"img":{"alt_text":"Secure Registration System with PHP and MySQL","src":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/posts\/secure-registration-system-php-mysql.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/posts\/secure-registration-system-php-mysql.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/posts\/secure-registration-system-php-mysql.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/posts\/secure-registration-system-php-mysql.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1335,"url":"https:\/\/hostscripter.com\/?p=1335","url_meta":{"origin":1352,"position":3},"title":"Part 4: Create your own Login System using PHP and MySql","author":"h05t5cr1pt3r","date":"November 28, 2022","format":false,"excerpt":"4. Authenticating Users with PHP Now that we have our database setup, we can go ahead and start coding with PHP. We're going to start with the authentication file, which will process and validate the form data that we'll send from our\u00a0index.html\u00a0file. Edit the\u00a0authenticate.php\u00a0file and add the following: <?php session_start();\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/hostscripter.com\/?cat=4"},"img":{"alt_text":"Authentication Incorrect Username PHP","src":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/authentication-incorrect-username.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/authentication-incorrect-username.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/authentication-incorrect-username.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/authentication-incorrect-username.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1333,"url":"https:\/\/hostscripter.com\/?p=1333","url_meta":{"origin":1352,"position":4},"title":"Part 3: Create your own Login System using PHP and MySql","author":"h05t5cr1pt3r","date":"November 28, 2022","format":false,"excerpt":"3. Creating the Database and setting-up Tables For this part, you will need to access your MySQL database, either using\u00a0phpMyAdmin\u00a0or your preferred MySQL database management application. Follow the below instructions if you're using\u00a0phpMyAdmin. Navigate to:\u00a0http:\/\/localhost\/phpmyadmin\/ Click the\u00a0Databases\u00a0tab at the top Under\u00a0Create database, enter\u00a0phplogin\u00a0in the text box Select\u00a0utf8_general_ci\u00a0as the collation Click\u00a0Create\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/hostscripter.com\/?cat=4"},"img":{"alt_text":"phpMyAdmin Accounts Table","src":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/phpmyadmin-accounts-table.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/phpmyadmin-accounts-table.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/phpmyadmin-accounts-table.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/phpmyadmin-accounts-table.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1339,"url":"https:\/\/hostscripter.com\/?p=1339","url_meta":{"origin":1352,"position":5},"title":"Part 6: Create your own Login System using PHP and MySql","author":"h05t5cr1pt3r","date":"November 28, 2022","format":false,"excerpt":"6. Creating the Profile Page The profile page will display the account information for the logged-in user. Edit the\u00a0profile.php\u00a0file and add the following code: <?php \/\/ We need to use sessions, so you should always start sessions using the below code. session_start(); \/\/ If the user is not logged in\u2026","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/hostscripter.com\/?cat=4"},"img":{"alt_text":"PHP Loggedin Profile Page","src":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/loggedin-profile-page.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/loggedin-profile-page.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/loggedin-profile-page.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codeshack.io\/web\/img\/phplogin\/loggedin-profile-page.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/hostscripter.com\/index.php?rest_route=\/wp\/v2\/posts\/1352"}],"collection":[{"href":"https:\/\/hostscripter.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostscripter.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostscripter.com\/index.php?rest_route=\/wp\/v2\/users\/301"}],"replies":[{"embeddable":true,"href":"https:\/\/hostscripter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1352"}],"version-history":[{"count":1,"href":"https:\/\/hostscripter.com\/index.php?rest_route=\/wp\/v2\/posts\/1352\/revisions"}],"predecessor-version":[{"id":1353,"href":"https:\/\/hostscripter.com\/index.php?rest_route=\/wp\/v2\/posts\/1352\/revisions\/1353"}],"wp:attachment":[{"href":"https:\/\/hostscripter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostscripter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostscripter.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}