Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] User Registration in PHP with Login: Form with MySQL and Code Download

#1
User Registration in PHP with Login: Form with MySQL and Code Download

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/01/user-registration-in-php-with-login-form-with-mysql-and-code-download.png" width="550" height="461" title="" alt="" /></div><div><p>Last modified on January 3rd, 2020 by Vincy.</p>
<p>Are you looking for code to create user registration in PHP? A lightweight form with MySQL database backend. Read on!</p>
<p>There are lots of PHP components for user registration available on the Internet. But these contain heavy stuff and lots of dependencies.</p>
<p>An appropriate code should be lightweight, secure, feature-packed and customizable. I am going to explain how to code this user registration in PHP with a login.</p>
<p>With this code, you can customize or put any add-ons as per your need and enhance it.</p>
<p><img class="alignnone size-large wp-image-10941" src="https://phppot.com/wp-content/uploads/2019/12/user-registration-in-php-with-login-form-550x461.png" alt="User Registration in PHP with Login Form" width="550" height="461" srcset="https://phppot.com/wp-content/uploads/2019/12/user-registration-in-php-with-login-form-550x461.png 550w, https://phppot.com/wp-content/uploads/20...00x251.png 300w, https://phppot.com/wp-content/uploads/20...68x644.png 768w, https://phppot.com/wp-content/uploads/20...n-form.png 940w" sizes="(max-width: 550px) 100vw, 550px"></p>
<h2>What is inside?</h2>
<ol>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#example-code-for-user-registration-in-php">Example code for user registration in PHP</a></li>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#create-user-registration-and-login-form">Create user registration and login form</a></li>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#registration-and-login-form-validation">Registration and login form validation</a></li>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#process-user-registration-in-php">Process user registration in PHP</a></li>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#php-login-authentication-code">PHP login authentication code</a></li>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#user-dashboard">User dashboard</a></li>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#mysql-database-script">MySQL database script</a></li>
<li><a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#screenshot-of-user-registration-and-login-form">Screenshot of user registration and login form</a></li>
</ol>
<h2 id="example-code-for-user-registration-in-php">Example code for user registration in PHP</h2>
<p>In this example, I have created user registration in PHP with the login script.&nbsp;In a previous article, we have seen <a href="https://phppot.com/php/php-login-script-with-session/">how to create a login script with PHP session</a>.</p>
<p>On a landing page, it shows a login form with a signup link. The registered user can enter their login details with the login form. Once done, he can get into the dashboard after authentication.</p>
<p>If the user does not have an account, then he can click the signup option to create a new account.</p>
<p>The user registration form requests username, email, password from the user. On submission, PHP code allows registration if the email does not already exist.</p>
<p>This example code has client-side validation for validating the entered user details.&nbsp;And also, it includes contains the server-side uniqueness test. The user email is the base to check uniqueness before adding the users to the MySQL database.</p>
<p>This linked article includes a basic example of implementing user registration in PHP and MySQL.</p>
<p><strong>File structure</strong></p>
<p><img class="alignnone size-full wp-image-10961" src="https://phppot.com/wp-content/uploads/2019/12/user-registration-file-structure.jpg" alt="User Registration File Structure" width="300" height="384" srcset="https://phppot.com/wp-content/uploads/2019/12/user-registration-file-structure.jpg 300w, https://phppot.com/wp-content/uploads/20...34x300.jpg 234w" sizes="(max-width: 300px) 100vw, 300px"></p>
<h2 id="create-user-registration-and-login-form">Create user registration and login form</h2>
<p>I have created three HTML view login form, registration form and the dashboard for this code.</p>
<p>Below HMTL code is for displaying the login form to the user. In this form, it has two inputs to allow the user to enter their username and password.</p>
<p>Without these details, a validation code will not allow the login to proceed. The login form tag’s on-click attribute is with loginValidation(). This function contains the login form validation script.</p>
<p>On submitting this login form, the PHP code will validate the user. If the users clear the authentication, then it will redirect him to the dashboard.</p>
<p>If the user attempts to log in with the wrong data, then the code will display a login error message in the login form. If you want to <a href="https://phppot.com/php/show-php-captcha-on-failed-login-attempts/">limit the failed login attempts</a>, the linked article has an example of that.</p>
<p>See also <a href="https://phppot.com/php/php-forgot-password-recover-code/">login form with forgot password</a> and <a href="https://phppot.com/php/secure-remember-me-for-login-using-php-session-and-cookies/">remember me</a>.</p>
<p class="code-heading">login-form.php</p>
<pre class="prettyprint">&lt;div class="sign-up-container"&gt; &lt;div class="login-signup"&gt; &lt;a href="user-registration-form.php"&gt;Sign up&lt;/a&gt; &lt;/div&gt; &lt;div class="signup-align"&gt; &lt;form name="login" action="" method="post" onsubmit="return loginValidation()"&gt; &lt;div class="signup-heading"&gt;Login&lt;/div&gt; &lt;?php if(!empty($loginResult)){?&gt; &lt;div class="error-msg"&gt;&lt;?php echo $loginResult;?&gt;&lt;/div&gt; &lt;?php }?&gt; &lt;div class="row"&gt; &lt;div class="inline-block"&gt; &lt;div class="form-label"&gt; Username&lt;span class="required error" id="username-info"&gt;&lt;/span&gt; &lt;/div&gt; &lt;input class="input-box-330" type="text" name="username" id="username"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="inline-block"&gt; &lt;div class="form-label"&gt; Password&lt;span class="required error" id="signup-password-info"&gt;&lt;/span&gt; &lt;/div&gt; &lt;input class="input-box-330" type="password" name="signup-password" id="signup-password"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;input class="sign-up-btn" type="submit" name="login-btn" id="login-btn" value="Login"&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; </pre>
<p>This is a user registration form getting minimal user data from the user. All form fields are mandatory.</p>
<p>It will pass-through a JavaScript validation before processing the user registration in PHP.</p>
<p>On submitting the registration form fields, it will invoke the&nbsp;signupValidation() JavaScript method. In this method, it validates with the non-empty check, email format, and the password match.</p>
<p>After validation, the PHP registration will take place with the posted form data.&nbsp;</p>
<p class="code-heading">user-registration-form.php</p>
<pre class="prettyprint">&lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;Registration&lt;/TITLE&gt; &lt;link href="./assets/css/phppot-style.css" type="text/css" rel="stylesheet" /&gt; &lt;link href="./assets/css/user-registration.css" type="text/css" rel="stylesheet" /&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;div class="phppot-container"&gt; &lt;div class="sign-up-container"&gt; &lt;div class="login-signup"&gt; &lt;a href="login-form.php"&gt;Login&lt;/a&gt; &lt;/div&gt; &lt;div class=""&gt; &lt;form name="sign-up" action="" method="post" onsubmit="return signupValidation()"&gt; &lt;div class="signup-heading"&gt;Registration&lt;/div&gt; &lt;?php if(!empty($registrationResponse["status"])) { ?&gt; &lt;?php if($registrationResponse["status"] == "error") { ?&gt; &lt;div class="server-response error-msg"&gt;&lt;?php echo $registrationResponse["message"]; ?&gt;&lt;/div&gt; &lt;?php } else if($registrationResponse["status"] == "success") { ?&gt; &lt;div class="server-response success-msg"&gt;&lt;?php echo $registrationResponse["message"]; ?&gt;&lt;/div&gt; &lt;?php } ?&gt; &lt;?php } ?&gt; &lt;div class="error-msg" id="error-msg"&gt;&lt;/div&gt; &lt;div class="row"&gt; &lt;div class="inline-block"&gt; &lt;div class="form-label"&gt; Username&lt;span class="required error" id="username-info"&gt;&lt;/span&gt; &lt;/div&gt; &lt;input class="input-box-330" type="text" name="username" id="username"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="inline-block"&gt; &lt;div class="form-label"&gt; Email&lt;span class="required error" id="email-info"&gt;&lt;/span&gt; &lt;/div&gt; &lt;input class="input-box-330" type="email" name="email" id="email"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="inline-block"&gt; &lt;div class="form-label"&gt; Password&lt;span class="required error" id="signup-password-info"&gt;&lt;/span&gt; &lt;/div&gt; &lt;input class="input-box-330" type="password" name="signup-password" id="signup-password"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="inline-block"&gt; &lt;div class="form-label"&gt; Confirm Password&lt;span class="required error" id="confirm-password-info"&gt;&lt;/span&gt; &lt;/div&gt; &lt;input class="input-box-330" type="password" name="confirm-password" id="confirm-password"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;input class="sign-up-btn" type="submit" name="signup-btn" id="signup-btn" value="Sign up"&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/BODY&gt; &lt;/HTML&gt; </pre>
<p><strong>Landing page loads login registration forms</strong></p>
<p class="code-heading">index.php</p>
<pre class="prettyprint">&lt;?php use Phppot\Member; session_start(); ?&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;user-registration&lt;/TITLE&gt; &lt;link href="./assets/css/phppot-style.css" type="text/css" rel="stylesheet" /&gt; &lt;link href="./assets/css/user-registration.css" type="text/css" rel="stylesheet" /&gt; &lt;script src="./vendor/jquery/jquery-3.3.1.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;div class="phppot-container"&gt; &lt;?php require_once "login-form.php";?&gt; &lt;/div&gt; &lt;/BODY&gt; &lt;/HTML&gt; </pre>
<p>And the below CSS is for presenting this example of user registration in PHP.</p>
<p class="code-heading">user-registration.css</p>
<pre class="prettyprint">.sign-up-container { border: 1px solid; border-color: #9a9a9a; background: #fff; border-radius: 4px; padding: 10px; width: 350px; margin: 50px auto; } .page-header { float: right; } .login-signup { margin: 10px; text-decoration: none; float: right; } .login-signup a { text-decoration: none; color: #000; font-weight: 700; } .signup-heading { font-size: 2em; font-weight: bold; padding-top: 60px; text-align: center; } .inline-block { display: inline-block; } .row { margin: 15px 0px; text-align: center; } .form-label { margin-bottom: 5px; text-align: left; } input.input-box-330 { width: 250px; } .sign-up-container .error { color: #ee0000; padding: 0px; background: none; border: #ee0000; } .sign-up-container .error-field { border: 1px solid #d96557; } .sign-up-container .error:before { content: '*'; padding: 0 3px; color: #D8000C; } .error-msg { padding-top: 10px; color: #D8000C; text-align: center; } .success-msg { padding-top: 10px; color: #23a600; text-align: center; } input.sign-up-btn { background-color: #ffb932; border-color: #ffc87a #e2a348 #da9d0a; text-align: center; cursor: pointer; color: #000; width: 250px } .signup-align { margin: 0 auto; } .page-content { font-weight: bold; padding-top: 60px; text-align: center; } </pre>
<h2 id="registration-and-login-form-validation">Registration and login form validation</h2>
<p>In this section, we are going to see the code created in <a href="https://phppot.com/jquery/jquery-form-validation-with-tooltip/">JavaScript for form validation</a>.</p>
<p>There are two methods for validating the form fields before sending the data to the PHP code.</p>
<p>On invalid data submission, the code will return a boolean false. It forces the user to enter the required fields by highlighting them.</p>
<p class="code-heading">login-form.php (JavaScript)</p>
<pre class="prettyprint lang-php">function loginValidation() { var valid = true; $("#username").removeClass("error-field"); $("#password").removeClass("error-field"); var UserName = $("#username").val(); var Password = $('#signup-password').val(); $("#username-info").html("").hide(); $("#email-info").html("").hide(); if (UserName.trim() == "") { $("#username-info").html("required.").css("color", "#ee0000").show(); $("#username").addClass("error-field"); valid = false; } if (Password.trim() == "") { $("#signup-password-info").html("required.").css("color", "#ee0000").show(); $("#signup-password").addClass("error-field"); valid = false; } if (valid == false) { $('.error-field').first().focus(); valid = false; } return valid; } </pre>
<p class="code-heading">user-registration-form.php (JavaScript)</p>
<pre class="prettyprint lang-php">function signupValidation() { var valid = true; $("#username").removeClass("error-field"); $("#email").removeClass("error-field"); $("#password").removeClass("error-field"); $("#confirm-password").removeClass("error-field"); var UserName = $("#username").val(); var email = $("#email").val(); var Password = $('#signup-password').val(); var ConfirmPassword = $('#confirm-password').val(); var emailRegex = /^[a-zA-Z0-9.!#$%&amp;'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; $("#username-info").html("").hide(); $("#email-info").html("").hide(); if (UserName.trim() == "") { $("#username-info").html("required.").css("color", "#ee0000").show(); $("#username").addClass("error-field"); valid = false; } if (email == "") { $("#email-info").html("required").css("color", "#ee0000").show(); $("#email").addClass("error-field"); valid = false; } else if (email.trim() == "") { $("#email-info").html("Invalid email address.").css("color", "#ee0000").show(); $("#email").addClass("error-field"); valid = false; } else if (!emailRegex.test(email)) { $("#email-info").html("Invalid email address.").css("color", "#ee0000") .show(); $("#email").addClass("error-field"); valid = false; } if (Password.trim() == "") { $("#signup-password-info").html("required.").css("color", "#ee0000").show(); $("#signup-password").addClass("error-field"); valid = false; } if (ConfirmPassword.trim() == "") { $("#confirm-password-info").html("required.").css("color", "#ee0000").show(); $("#confirm-password").addClass("error-field"); valid = false; } if(Password != ConfirmPassword){ $("#error-msg").html("Both passwords must be same.").show(); valid=false; } if (valid == false) { $('.error-field').first().focus(); valid = false; } return valid; } </pre>
<h2 id="process-user-registration-in-php">Process user registration in PHP</h2>
<p>After submitting the form details, it processes user registration in the PHP code.</p>
<p>This code uses default form submit to post data to the PHP. If you want the <a href="https://phppot.com/php/ajax-based-login-registration-system-with-jquery-lightbox/">user registration code with AJAX</a>, then we have to prevent the default submit with a script.</p>
<p>I have added this code at the beginning of the user-registration-form.php. It checks if the user submitted the form. Then, it invokes the registerMember() method defined in the Member model.</p>
<p class="code-heading">login-form.php (PHP code)</p>
<pre class="prettyprint lang-php">&lt;?php use Phppot\Member; if (! empty($_POST["signup-btn"])) { require_once './Model/Member.php'; $member = new Member(); $registrationResponse = $member-&gt;registerMember(); } ?&gt; </pre>
<p>I have shown the Member model class code below. It contains all the functions related to this user registration and login example.</p>
<p>In the&nbsp;<em>registerMember()</em> function, it checks if the posted email already exists. If so, it truncates the registration flow and returns the error. Otherwise, it creates the Insert query to add the member record into the MySQL database.</p>
<p>The&nbsp;<em>loginMember()</em> function checks if there is any match for the entered login details. If the match found, it clears the authentication and allows the user to access the&nbsp;<em>dashboard.</em></p>
<p class="code-heading">Model/Member.php</p>
<pre class="prettyprint">&lt;?php namespace Phppot; class Member { private $ds; function __construct() { require_once __DIR__ . './../lib/DataSource.php'; $this-&gt;ds = new DataSource(); } public function isMemberExists($email) { $query = 'SELECT * FROM tbl_member where email = ?'; $paramType = 's'; $paramValue = array( $email ); $insertRecord = $this-&gt;ds-&gt;select($query, $paramType, $paramValue); $count = 0; if (is_array($insertRecord)) { $count = count($insertRecord); } return $count; } public function registerMember() { $result = $this-&gt;isMemberExists($_POST["email"]); if ($result &lt; 1) { if (! empty($_POST["signup-password"])) { $hashedPassword = password_hash($_POST["signup-password"], PASSWORD_DEFAULT); } $query = 'INSERT INTO tbl_member (username, password, email) VALUES (?, ?, ?)'; $paramType = 'sss'; $paramValue = array( $_POST["username"], $hashedPassword, $_POST["email"] ); $memberId = $this-&gt;ds-&gt;insert($query, $paramType, $paramValue); if(!empty($memberId)) { $response = array("status" =&gt; "success", "message" =&gt; "You have registered successfully."); } } else if ($result == 1) { $response = array("status" =&gt; "error", "message" =&gt; "Email already exists."); } return $response; } public function getMember($username) { $query = 'SELECT * FROM tbl_member where username = ?'; $paramType = 's'; $paramValue = array( $username ); $loginUser = $this-&gt;ds-&gt;select($query, $paramType, $paramValue); return $loginUser; } public function loginMember() { $loginUserResult = $this-&gt;getMember($_POST["username"]); if (! empty($_POST["signup-password"])) { $password = $_POST["signup-password"]; } $hashedPassword = $loginUserResult[0]["password"]; $loginPassword = 0; if (password_verify($password, $hashedPassword)) { $loginPassword = 1; } if ($loginPassword == 1) { $_SESSION["username"] = $loginUserResult[0]["username"]; $url = "./home.php"; header("Location: $url"); } else if ($loginPassword == 0) { $loginStatus = "Invalid username or password."; return $loginStatus; } } } </pre>
<h2 id="php-login-authentication-code">PHP login authentication code<br /></h2>
<p>Below PHP code is for invoking the authentication function after login. It is in the login-form.php file above the HTML code.</p>
<p class="code-heading">user-registration-form.php (PHP Code)</p>
<pre class="prettyprint lang-php">&lt;?php if (! empty($_POST["login-btn"])) { require_once './Model/Member.php'; $member = new Member(); $loginResult = $member-&gt;loginMember(); } ?&gt; </pre>
<h2 id="user-dashboard">User dashboard</h2>
<p>This is the user dashboard HTML code. It shows a welcome message with the logged-in member name. It also has an option to logout from the current session.</p>
<p class="code-heading">home.php</p>
<pre class="prettyprint lang-php">&lt;?php session_start(); $username = $_SESSION["username"]; ?&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;TITLE&gt;Welcome&lt;/TITLE&gt; &lt;link href="./assets/css/phppot-style.css" type="text/css" rel="stylesheet" /&gt; &lt;link href="./assets/css/user-registration.css" type="text/css" rel="stylesheet" /&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;div class="phppot-container"&gt; &lt;div class="page-header"&gt; &lt;span class="login-signup"&gt;&lt;a href="login-form.php"&gt;Logout&lt;/a&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class="page-content"&gt;Welcome &lt;?php echo $username;?&gt;&lt;/div&gt; &lt;/div&gt; &lt;/BODY&gt; &lt;/HTML&gt; </pre>
<p class="code-heading">DataSource.php</p>
<pre class="prettyprint lang-php">&lt;?php /** * Copyright © 2019 Phppot * * Distributed under MIT license with an exception that, * you don’t have to include the full MIT License in your code. * In essense, you can use it on commercial software, modify and distribute free. * Though not mandatory, you are requested to attribute this URL in your code or website. */ namespace Phppot; /** * Generic datasource class for handling DB operations. * Uses MySqli and PreparedStatements. * * @version 2.5 - recordCount function added */ class DataSource { // PHP 7.1.0 visibility modifiers are allowed for class constants. // when using above 7.1.0, declare the below constants as private const HOST = 'localhost'; const USERNAME = 'root'; const PASSWORD = 'test'; const DATABASENAME = 'user-registration'; private $conn; /** * PHP implicitly takes care of cleanup for default connection types. * So no need to worry about closing the connection. * * Singletons not required in PHP as there is no * concept of shared memory. * Every object lives only for a request. * * Keeping things simple and that works! */ function __construct() { $this-&gt;conn = $this-&gt;getConnection(); } /** * If connection object is needed use this method and get access to it. * Otherwise, use the below methods for insert / update / etc. * * @return \mysqli */ public function getConnection() { $conn = new \mysqli(self::HOST, self::USERNAME, self::PASSWORD, self::DATABASENAME); if (mysqli_connect_errno()) { trigger_error("Problem with connecting to database."); } $conn-&gt;set_charset("utf8"); return $conn; } /** * To get database results * * @param string $query * @param string $paramType * @param array $paramArray * @return array */ public function select($query, $paramType = "", $paramArray = array()) { $stmt = $this-&gt;conn-&gt;prepare($query); if (! empty($paramType) &amp;&amp; ! empty($paramArray)) { $this-&gt;bindQueryParams($stmt, $paramType, $paramArray); } $stmt-&gt;execute(); $result = $stmt-&gt;get_result(); if ($result-&gt;num_rows &gt; 0) { while ($row = $result-&gt;fetch_assoc()) { $resultset[] = $row; } } if (! empty($resultset)) { return $resultset; } } /** * To insert * * @param string $query * @param string $paramType * @param array $paramArray * @return int */ public function insert($query, $paramType, $paramArray) { $stmt = $this-&gt;conn-&gt;prepare($query); $this-&gt;bindQueryParams($stmt, $paramType, $paramArray); $stmt-&gt;execute(); $insertId = $stmt-&gt;insert_id; return $insertId; } /** * To execute query * * @param string $query * @param string $paramType * @param array $paramArray */ public function execute($query, $paramType = "", $paramArray = array()) { $stmt = $this-&gt;conn-&gt;prepare($query); if (! empty($paramType) &amp;&amp; ! empty($paramArray)) { $this-&gt;bindQueryParams($stmt, $paramType, $paramArray); } $stmt-&gt;execute(); } /** * 1. * Prepares parameter binding * 2. Bind prameters to the sql statement * * @param string $stmt * @param string $paramType * @param array $paramArray */ public function bindQueryParams($stmt, $paramType, $paramArray = array()) { $paramValueReference[] = &amp; $paramType; for ($i = 0; $i &lt; count($paramArray); $i ++) { $paramValueReference[] = &amp; $paramArray[$i]; } call_user_func_array(array( $stmt, 'bind_param' ), $paramValueReference); } /** * To get database results * * @param string $query * @param string $paramType * @param array $paramArray * @return array */ public function getRecordCount($query, $paramType = "", $paramArray = array()) { $stmt = $this-&gt;conn-&gt;prepare($query); if (! empty($paramType) &amp;&amp; ! empty($paramArray)) { $this-&gt;bindQueryParams($stmt, $paramType, $paramArray); } $stmt-&gt;execute(); $stmt-&gt;store_result(); $recordCount = $stmt-&gt;num_rows; return $recordCount; } } </pre>
<h2 id="mysql-database-script">MySQL database script</h2>
<p>Below SQL script shows the MySQL database table’s create statement. It also has the specification for the key and indexes.</p>
<p><a href="https://phppot.com/wp-content/uploads/2019/12/user-registration-mysql-schema.jpg"><img class="alignnone size-large wp-image-10951" src="https://phppot.com/wp-content/uploads/2019/12/user-registration-mysql-schema-550x97.jpg" alt="User registration MySQL schema" width="550" height="97" srcset="https://phppot.com/wp-content/uploads/2019/12/user-registration-mysql-schema-550x97.jpg 550w, https://phppot.com/wp-content/uploads/20...300x53.jpg 300w, https://phppot.com/wp-content/uploads/20...68x136.jpg 768w, https://phppot.com/wp-content/uploads/20...schema.jpg 1200w" sizes="(max-width: 550px) 100vw, 550px"></a></p>
<p>Import this script into your PHP development root to execute this example.</p>
<p class="code-heading">sql/user-registration.sql</p>
<pre class="prettyprint lang-php">-- -- Database: `user-registration` -- -- -------------------------------------------------------- -- -- Table structure for table `tbl_member` -- CREATE TABLE `tbl_member` ( `id` int(11) NOT NULL, `username` varchar(255) NOT NULL, `password` varchar(200) NOT NULL, `email` varchar(255) NOT NULL, `create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for dumped tables -- -- -- Indexes for table `tbl_member` -- ALTER TABLE `tbl_member` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `tbl_member` -- ALTER TABLE `tbl_member` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; </pre>
<h2 id="screenshot-of-user-registration-and-login-form">Screenshot of user registration and login form</h2>
<p>Login form with validation response:</p>
<p><img class="alignnone size-full wp-image-10937" src="https://phppot.com/wp-content/uploads/2019/12/user-login-form-output.jpg" alt="User Login Form Output" width="387" height="331" srcset="https://phppot.com/wp-content/uploads/2019/12/user-login-form-output.jpg 387w, https://phppot.com/wp-content/uploads/20...00x257.jpg 300w" sizes="(max-width: 387px) 100vw, 387px"></p>
<p>User registration form server-side validation response:</p>
<p><img class="alignnone size-full wp-image-10938" src="https://phppot.com/wp-content/uploads/2019/12/screenshot-user-registration-in-php.jpg" alt="Screenshot User Registration in-php PHP" width="387" height="491" srcset="https://phppot.com/wp-content/uploads/2019/12/screenshot-user-registration-in-php.jpg 387w, https://phppot.com/wp-content/uploads/20...36x300.jpg 236w" sizes="(max-width: 387px) 100vw, 387px"></p>
<p><a class="download" href="https://phppot.com/downloads/user-registration-in-php-with-login-form-with-mysql-and-code-download.zip">Download</a></p>
<p> <!-- #comments --> </p>
<div class="related-articles">
<h2>Popular Articles</h2>
</p></div>
<p> <a href="https://phppot.com/php/user-registration-in-php-with-login-form-with-mysql-and-code-download/#top" class="top">↑ Back to Top</a> </p>
</div>


https://www.sickgaming.net/blog/2019/12/...-download/
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016