how to make a sign-up database

<?php
session_start();

// initializing variables
$username = "";
$email    = "";
$errors = array(); 

// connect to the database
$db = mysqli_connect('localhost', 'root', '', 'registration');

// REGISTER USER
if (isset($_POST['reg_user'])) {
  // receive all input values from the form
  $username = mysqli_real_escape_string($db, $_POST['username']);
  $email = mysqli_real_escape_string($db, $_POST['email']);
  $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
  $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);

  // form validation: ensure that the form is correctly filled ...
  // by adding (array_push()) corresponding error unto $errors array
  if (empty($username)) { array_push($errors, "Username is required"); }
  if (empty($email)) { array_push($errors, "Email is required"); }
  if (empty($password_1)) { array_push($errors, "Password is required"); }
  if ($password_1 != $password_2) {
	array_push($errors, "The two passwords do not match");
  }

  // first check the database to make sure 
  // a user does not already exist with the same username and/or email
  $user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";
  $result = mysqli_query($db, $user_check_query);
  $user = mysqli_fetch_assoc($result);
  
  if ($user) { // if user exists
    if ($user['username'] === $username) {
      array_push($errors, "Username already exists");
    }

    if ($user['email'] === $email) {
      array_push($errors, "email already exists");
    }
  }

  // Finally, register user if there are no errors in the form
  if (count($errors) == 0) {
  	$password = md5($password_1);//encrypt the password before saving in the database

  	$query = "INSERT INTO users (username, email, password) 
  			  VALUES('$username', '$email', '$password')";
  	mysqli_query($db, $query);
  	$_SESSION['username'] = $username;
  	$_SESSION['success'] = "You are now logged in";
  	header('location: index.php');
  }
}

// ... 

4.5
4
Phoenix Logan 186120 points

                                    &lt;html&gt;
&lt;head&gt;
&lt;title&gt;PHP User Registration Form&lt;/title&gt;
&lt;link href=&quot;./css/style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form name=&quot;frmRegistration&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
        &lt;div class=&quot;demo-table&quot;&gt;
        &lt;div class=&quot;form-head&quot;&gt;Sign Up&lt;/div&gt;
            
&lt;?php
if (! empty($errorMessage) &amp;&amp; is_array($errorMessage)) {
    ?&gt;	
            &lt;div class=&quot;error-message&quot;&gt;
            &lt;?php 
            foreach($errorMessage as $message) {
                echo $message . &quot;&lt;br/&gt;&quot;;
            }
            ?&gt;
            &lt;/div&gt;
&lt;?php
}
?&gt;
            &lt;div class=&quot;field-column&quot;&gt;
                &lt;label&gt;Username&lt;/label&gt;
                &lt;div&gt;
                    &lt;input type=&quot;text&quot; class=&quot;demo-input-box&quot;
                        name=&quot;userName&quot;
                        value=&quot;&lt;?php if(isset($_POST['userName'])) echo $_POST['userName']; ?&gt;&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            
            &lt;div class=&quot;field-column&quot;&gt;
                &lt;label&gt;Password&lt;/label&gt;
                &lt;div&gt;&lt;input type=&quot;password&quot; class=&quot;demo-input-box&quot;
                    name=&quot;password&quot; value=&quot;&quot;&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field-column&quot;&gt;
                &lt;label&gt;Confirm Password&lt;/label&gt;
                &lt;div&gt;
                    &lt;input type=&quot;password&quot; class=&quot;demo-input-box&quot;
                        name=&quot;confirm_password&quot; value=&quot;&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field-column&quot;&gt;
                &lt;label&gt;Display Name&lt;/label&gt;
                &lt;div&gt;
                    &lt;input type=&quot;text&quot; class=&quot;demo-input-box&quot;
                        name=&quot;firstName&quot;
                        value=&quot;&lt;?php if(isset($_POST['firstName'])) echo $_POST['firstName']; ?&gt;&quot;&gt;
                &lt;/div&gt;

            &lt;/div&gt;
            &lt;div class=&quot;field-column&quot;&gt;
                &lt;label&gt;Email&lt;/label&gt;
                &lt;div&gt;
                    &lt;input type=&quot;text&quot; class=&quot;demo-input-box&quot;
                        name=&quot;userEmail&quot;
                        value=&quot;&lt;?php if(isset($_POST['userEmail'])) echo $_POST['userEmail']; ?&gt;&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;field-column&quot;&gt;
                &lt;div class=&quot;terms&quot;&gt;
                    &lt;input type=&quot;checkbox&quot; name=&quot;terms&quot;&gt; I accept terms
                    and conditions
                &lt;/div&gt;
                &lt;div&gt;
                    &lt;input type=&quot;submit&quot;
                        name=&quot;register-user&quot; value=&quot;Register&quot;
                        class=&quot;btnRegister&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

4.5 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to make login and registration form in php how to create register and login page in php login registered user php php registration and login User Registration in PHP tutorial php login and register make a login and register using php how to connect username and login page in php how to create registration and login form in php user register and login in php mysql php register login example how to make login and registration form in php with mysql login user automatically after registration php create a login and registration page in php user account page php Create PHP Login and Registration Pages. login and register using php simple login and registration in php php login register app php form registration and login user registration form in php login or register php create a login registration page connect wiith php how to login a user in php step by step registration and login in php and mysql login and registration in php user login registration php mysql simole login page with username and password in php login and show registration details php wel come login username php php login registration form make login and registration in php localhost/user_registration/login.php registration and login system using the PHP and MySQL login and register website in php php user registration form register and login page in php with database php user login log login registration php mysql login registration form in php creating a registration and login app using php and mysql php mysql login and registration simple php &amp; mysql login and registration system with profile php user login code login registration form php mysql login and register page php creating a login and register page in php login cek user name php register login php login register in php php login and registration User registration using php and php login and registration php PHP 7 login and registration form user registration and login php register and login php login and register php with database login and registration system in php with dashboard how to create login and registration page in php registration username and password php create user registration with php user account page using php how to make login and registration form in php and mysql php code for user login and user registration login registration in php php login / register login and registration form with database in php php project example login and register login / register php login and register in php php mysql login and registration form php mysql login registration localhost/user registration/login.php php register and login form simple php login and registration system php login register php login and registration form simple best login and registration php registration and login form in php basic registration and login form in php steps simple registration and login form in php php login and register tutorial user login and registration php register and login page php login and register system php php online registration system registration form in php and with first name second name and last on on one line how to make a registration form in php and mysql user registration php online code editor singup php mysql complete code register a new user php simple php login and registration script php login register mysql after registration create id php php website regerestring page mysql form registration php mysql php signup sign in and sign up code in php php login register form mysql user registration in php php login register form login form and registration form in php php mysql signup form how to make register and login php user registration and login in php php system login and register simple login page in html with database connection PHP: Complete Login and Registration System with PHP &amp; MYSQL free store user registration data into database php signup form source code user register form in php database chart register form php mysql source code for user login using image dataset php login registration system source code free download registration.php file localhost/registration/register.php employee registration php login and registration codewithawa sign up system php store register to database php register php from database registeration in php PHP Complete Registration and Login System Using MySQLi PHP Complete Registration &amp; Login System Using MySQLi register form php student registration form in php login and registration form in php and mysql with session login registre system in html register in php mysql registration form using php PHP: COMPLETE LOGIN AND REGISTRATION SYSTEM WITH PHP &amp; MYSQL user registration php registration form php mysql source code user registration form php php simple user registration form oop php sign up and login page php simple user registration form php register user login register form in php singup.php php register and login user registration system using php and mysql registration system php mysql login register system how to create a login and registration page in php user registration system using javascript how to make user registration work html create registration login php mysql login register profile php how to make a login and signup page in php function for registering a user in php log in registration page in html css with database how to make registration form in php sql that can only make one account complete user registration system using php and mysql database register time php how to create a patient registration form php mysql how to registration and login php connection in one page php register code php registratiob how to create register php register user php resgistered users details update using php register a user php how to create a registration form in php and mysql how to ensure users complete their remaining fields after registration using php, mysql and javascript php registration login how to connect registration form after login registration form phpmyadmin registration form mysql php editor php register how to register user php register in php open source complete registration system php open source registration system php oocalhost/usersignup/Register.php php source code for login and registration page register a new account php php login and signup system registraion use diffent type in php login and registration in php source code login/register code connecting signup form to php php PHP Login and Registration System php mysql form registration php registration form with database create signup login php registration form connect to database in php login and registration form in php total register database php php user login Register user on phpmyadmin html php registration form using mysql localhostregistration.php how to connect php signup form with database register from sdb log login in php how to register using php implementing php register database sigup sign in register page using php make a register page with php register login code php javascript php registration form code log in and sign up database php registration example sign up and login database php create account page login and registration form in php using session registration page in php php register page login and register source code localregisterhost/loginpage/registration.php signup php code login and register form in php login registration database php/registration and login form sign up script php creating a class registration system mysql add user form in php login register php log in and signup form in php and connect to database mysql registration form php source code registration php source code Login and Register system login and registration form in php with mysql database sign up and login php all steps to do in creating a php code for registering a user registration page .php php code for login and registration form with mysql database how to make a signup and login php sign up php registration php mysql code registeta user form POST mysql php html registration form mysql html registration form login to phpmyadmin registration system php registration page using php registration user on mysql with php and login php login and registration source code php register login and input signup form php mysql register users on mysql with php and manage them php register form with mysql signup mysql query sign up in php mysql register page php register.php php register with mysql database loalhost/5417/userRegister.html create database for sign up register system php mysql php user reigsterition action= php code for a registration form login signup page in php with mysql database source code sql register and login form registration and login form in php and mysql if registration success perform this php code how to make php registration and login form users registration php mysql register form code php does user registration save to sql database How to make a sign up form using php and mariaDB How to make a sign up form using php and amriaDB PHP: Complete Login and Registration System with PHP how to connect register page to database mysql php sign up registration user in php mysql complete registration form in php registration page database query script register php register form mysql php php user registration script php code for registration form with database user registration database design simple user registration my sql registration system php and mysql how to create a register with statement using php how to create a register form using php HOW TO MAKE USER LOGIN OR REGISTER SYSTEM IN BLOGER php user register script php user signup and login how to create a Counseling website which registered user can chat and share file using php and mysql php mysql signup how to make a registration and login in html with database html php signup html php registration php registration and login form login registration form code php bhest why to make register how to make a register and login system in html php form registration login and register php php login register template mysql register mysql database register php register script form registration in php with awa database create table registration system php user login and rehistratuion systen login and register html php sign-up and login system in php registration form in php signup and login form in php login and register php code login and registration using php php register user to database php login and register page how to make a login/register system how to make a login/register registewr page with php Create a database on MySQL, create a Login Page and Registration Page from where students can register using name, email, password, and class and login using email and password. php registration form with mysql login and register using php mysql css and html how to create login and register with php php login register user php code for customer registration registration system in php and mysql simple registration form in php with database download registration and login form php mysql php and mysql registration form php register mysql php register system php: complete login and registration system with php &amp; mysql download registration system in php PHP Complete Registration &amp; Login System Using MySQLi - Complete Guide php registration system how to create a register form php mysql how to make register form php sql php regisration page keeps loading registration form in php and mysql How To Make Login &amp; Registration Form In PHP And MySql, Create SignIn &amp; SignUp Page login and signup using php and mysql login sign up php login user after registeration form php class register user php php Singup user registration table php signup form in php and mysql complete login and register system php php Sign Up how to make a login and register form in php php sign up form php registration login and signup page in php mysql registration database register login php mysql database code register login php mysql database php user registration php registration code with file php registration code register system php PHP registe user mysql how to create user login and user register system in and signup function php sql signup function php sqlp full login + register system source php sql account registration form register php msql How to registration form using php and mysql registration php code localhpst/register/user-registration-in-php-with-login-form-with-mysql-and-code-download/user-registration-form.php login and registration form in php and mysql register php register php mysql php register form registration form php register and login php sql login and registration php mysql how to make a register system with php and javascript php login system php registration form how to add gcphone to your database django user registration and login example add database online Multi User Login oop PHP and MySql php login system with session registration page with form and php sign-up database how to make a sign-up database registration php how to create a account with php html php mysql register and login php user login and registration
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source