November 20, 2013 6:06 am

How to create Login and Signup System in PHP

Received many request from PHP web developer for very basic article to create login and signup page in php. This article is totally for PHP developers who is very new in programming. In this tutorial I have created 2 forms for login and signup with code download and a demo.

How to create Login and Signup form in PHP

Database Details:

database name => phpgang

table name => users

db.sql

Database file run in your MySQL to create database and add data in table.

db.php

Edit this file as per your database credentials.

This time I have used mysqli_connect as mysql_connect is deprecated in PHP 5.5 so web developers start shifting your apps to mysqli.

Now come to the main index file in this index file i have done all work like forms and php code to signup and login users.

Note: MD5 is no more secure passwords so please use this class for passwords: How to Hashing Password in PHP 5.5 with Password Hashing API

In signup process we are checking email validation (!filter_var($email, FILTER_VALIDATE_EMAIL)) and duplicate email no more than one account with single email and encrypt your password with md5().

In demo design i have used jQuery UI tabs and create some css effect on input boxes.

CSS to show input boxes effects:

If you have any problem regarding this tutorial configuration please feel free to comment we love to answer your queries.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.


Tutorial Categories:
  • siddhu

    nice but little bit lengthy..

  • Anthony

    can you show password recovery(forgot password) function ? via email i think.
    thanks in advance !

  • Anthony

    forgot password function will ba very helpful ! Regards !

  • Anthony

    “Remember me” checkbox will be great too !

  • bob

    Agree with Anthony -(remember me) function will be awesome!

  • Shahbaz Ahmed Bhatti

    Why we useWhy we USe this mysqli_real_escape_string

    What is Purpose o fthese Function

    • Bill gates

      To protect you from attacker that using sql injection to hack your website

    • asz

      can u pls send me the code?

  • asz

    i couldnt download the code although already subscribed

    • jenilisa

      save the webpage dear.

  • gani

    not able to insert record in database using sign up form.

  • zppinto

    Some mistakes I’ve found and respective corrections…

    1. Missing semicolon after CURRENT_TIMESTAMP.
    2. Change line 38 to mysqli and don’t forget to add the $connection parameter.
    3. Add echo $message on line 41 to see the errors.

  • techviha.com

    nice article, i have done this. 🙂 ty for sharing

  • ARUN DANEGOUDAR

    I’m working with bootstrap framework …
    $message not working….

  • Alndoah

    Where can I find the member’s area after login tutorial?

  • ravi

    i am getting error .
    i am using mysql database , should i use mysql instead of mysqli in code of php.

    • Greg Brow

      Line 38 change to.
      mysqli_query($connection,”insert into users(name,email,password) values(‘”.$name.”‘,'”.$email.”‘,'”.md5($password).”‘)”);

  • ravi

    how should i name the database db.sql . and what should be the name of css file

  • esteban Peralta

    mysqli_real_escape_string() expects parameter 1 to be mysqli

    help u.u

  • rubab

    having problem with the layout.css is not working for me

  • preet

    do i have make 1 file or 3 files for this coding. thanks

  • preet

    hi i am creating online we store and i want make signup and login form. i dont know php please can some one write full coding for me please i need to make login and signup form on my web store my database name is “phpgang” and table name is “users”………please some one help me thanks a lot in advance

    • Naseha Sameen

      were you able to create the page

  • Gustavo Rocha

    Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:wampwwwphpgangindex.php on line 38

  • Goutham

    while login it shows only the message . i need a secure login process for a page where only a members can access the page?

  • Gustavo Rocha

    still: Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:wampwwwphpgangindex.php on line 38

  • Eloi Vicenç Gonzalez Mas

    How can I make a login form that redirects each user to its OWN page so that only that user sees that page?

    Thanks in advice!

  • Qaisar Khan

    Great website great article many thanks 🙂 Sir

  • Naseha Sameen

    New to this php, learning … I tried using this code, but it does not insert any record to the table.

    Can you help me.

    • You must got some error try to debug and send error.

      • Ashish Tomar

        do i have to link this index file with any html file to see those forms in google chrome. because when i opened index.php in chrome it showed me source code not the forms to login and signup.rep asap

  • Prakash

    The files in download are correct but the code written above has errors.

    Lot of unclear points…….

    1.What is the name of main php page ?
    2.What is the name of .css file ?
    3.Where to put the css code ?

    Error correction:

    There should be a comma after
    date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP

    like
    date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

    There is no “forget password” option in the downloaded code too.

  • Ashish Tomar

    @huzoorbux :disqus do i have to link this index file with any html file to see those forms in google chrome. because when i opened index.php in chrome it showed me source code not the forms to login and signup.rep asap

  • Billions

    please i have downloaded the code, am running apache server but still get this error, Need some help

    Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:xampphtdocslogin-signup-in-phpdb.php on line 2

    Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:xampphtdocslogin-signup-in-phpdb.php on line 2

    Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:xampphtdocslogin-signup-in-phpdb.php on line 2

    thank you for helping.having a project i need to fix

    • lahiru

      for issue no 1 and 2 update db.php according to your apache setup

    • Patrick Weaver

      I had the same problem and went around it by pasting the table rules into phpmyadmin createtable screen (after I had created the database: db.mysql)

  • jonthan

    #1064 – You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use near
    ‘(id)
    ) ENGINE=MyISAM’ at line 7 how to fix

    • On which page you are getting this error and which version of mysql you are using?

    • Kim Kyungmin

      date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY(id)

      He missed comma.
      CURRENT_TIMESTAMP,

  • Golda-Lee Sawyers

    Thanks for the article, I am having an issue with line 98 ‘.$message.’. This is my error:

    Notice: Undefined variable: message in C:wampwwwPUNISHMENTindex.php on line 98

  • Golda-Lee Sawyers

    Thank you for this post, very helpful.

  • Delawar

    using pdo registration + sign up source code????

  • munawar

    what is the purpose of using real escape string function ??

    • Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.

    • Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.

    • Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.

  • Neha Bethu

    where should i include this css script??? plz post the answer immediatly

  • Alberto Giardino

    css Does not work…

    • Omer Latif

      change at the end to