Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Tuesday, February 27, 2018

Simple login form using PHP and MySQL.

The login form is very much essential in every kind of web application so here we are explaining a simple and best way of doing login system. which mainly includes 
1. Connecting to Database
2. Login(Session Start)
3. Logout(Session End)
4. Session Check
5. Login Form
6. CSS

1. Connecting to Database

$DatabaseServer = "localhost";
$DatabaseUsername = "root";
$DatabasePassword = "root";
$DatabaseName = "demo";

$Connection = mysqli_connect($DatabaseServer, $DatabaseUsername, $DatabasePassword, $DatabaseName);

if ($Connection === false) {
    die("ERROR: Could not connect. " . mysqli_connect_error());
}



2. Login

session_start();
if (isset($_POST['username']) and isset($_POST['password'])) {
   
    $Username = $_POST['username'];
    $Password = $_POST['password'];
    $query = "SELECT * FROM `user` WHERE FirstName='$Username' and Password='$Password'";
    $result = mysqli_query($Connection, $query) or die(mysqli_error($connection));
    $count = mysqli_num_rows($result);

    if ($count == 1) {
        $_SESSION['username'] = $
Username;
    } else {
        $fmsg = "Invalid Login Credentials.";
    }
}


3. Logout

session_start();
session_destroy();
header('Location: login.php');


4. Session Check

if (isset($_SESSION['username'])) {
    
    echo "<div class='session-box'>";
    echo 'Welcome Mr.'.$Username = $_SESSION['username'];
    echo "<br><a href='logout.php'>Logout</a>";
    echo "</div>";
}else{
    
    echo "<div class='session-box'>";
    echo "You are logged out.";
    echo "</div>";

}

5. Login Form

<form method="POST" class="login-box">

    <div class="form-header">Please Login</div>

    <div class="col-md-12">  
        <label>Username</label>
        <input type="text" name="username" class="form-control" placeholder="Username" required>
    </div>

    <div class="col-md-12">
        <label>Password</label>
        <input type="password" name="password" class="form-control" placeholder="Password" required>
    </div>

    <div class="col-md-6">
        <button class="btn btn-primary" type="submit">Login</button>
    </div>

</form>

6.CSS

 <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <style>
            .login-box{
                position: absolute;
                width: 300px;
                height: 270px;
                z-index: 15;
                top: 50%;
                left: 50%;
                margin: -100px 0 0 -150px;
                border: 1px solid #8080804a;
                border-radius: 5px;
                background: #8080804a;
            }
            .session-box{
                position: absolute;
                width: 300px;
                height: 100px;
                z-index: 15;
                top: 10%;
                left: 50%;
                margin: 0px 0 0 -150px;
                border: 1px solid #8080804a;
                border-radius: 5px;
                background: #8080804a;
                padding: 30px;
            }
            .form-control{
                padding: 10px;
                margin-top: 5px;
            }
            .btn-primary{
                margin-top: 20px;
            }
            .form-header{
                width: 299px;
                height:40px;
                background: #004f61;
                color:white;
                text-align: center;
                font-size: 20px;
                margin-bottom: 20px;
                padding: 5px;
            }
        </style>

    </head>

Create Database Table

CREATE TABLE `user` (
  `UserID` int(12) NOT NULL,
  `FirstName` varchar(48) NOT NULL,
  `LastName` varchar(48) NOT NULL,
  `Email` varchar(128) NOT NULL,
  `Password` varchar(20) NOT NULL,
  `City` varchar(48) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


INSERT INTO `user` (`UserID`, `FirstName`, `LastName`, `Email`, `Password`, `City`) VALUES
(7, 'Rahul', 'Rajshekaran', 'Rahul@zzz.xxx', 'Rahul@123', 'Pune'),
(8, 'Mahesh', 'Krishna', 'Mahesh@xxx.xxx', 'Mahesh@123', 'Delhi');







Result




55 comments:

  1. Well done! you do a good job. but)) where is the salt? where md5? Young should immediately get used to a certain order! I think so. subjectively of course))

    ReplyDelete
  2. Glance complicated in order to much added in pleasant from you!Lighting Warehouse Sydney

    ReplyDelete
  3. June Florist - Same day flower delivery singapore. Call June Florist for floral arrangements for wedding, decorations for conferences, hand banquet decorations, Flower Box, table flower arrangement & more. Tel: +65 6282 7555
    order flower bouquet online
    florist online shop

    ReplyDelete
  4. We offer university assignment help fulfilling the specific and precise needs of students. Poor quality of an assignment drastically affects the score sheet of a student. Here at Calltutors.com, the writers know how to proceed with an assignment writing task to make the end-result appreciable with world-class university assignment help online. We even welcome the feedback from the client’s end and try to sort out the shortcomings as soon as possible.
    https://www.calltutors.com/Articles/Writing-Assignment-for-University

    ReplyDelete
  5. Thanks for the great writeup. This the fact is once were some sort of pleasure bank account this.High Bay Led Lighting

    ReplyDelete
  6. it’s great post.i learn something new.i’ll try it my own.
    sign in hotmail
    hotmail sign up login

    ReplyDelete
  7. We provide you support to handle your roadrunner email account efficiently. Roadrunner Phone Number +1-888-338-6033 enable you to get associated with remote professionals effectively and in a flash. We give 24x7 days roadrunner client support service.

    ReplyDelete
  8. Thank you so much for providing such a useful information.

    If you are a Kaspersky user and face with the technical problem that attacks the functionality presentation of this antivirus software on your desktop, then Kaspersky Technical Support is right here to support you online and resolve all the problem.

    kaspersky help support
    kaspersky help support
    Kaspersky Tech Help
    Kaspersky Antivirus Support
    Kaspersky Technical Support
    Kaspersky Online Tech Support
    Kaspersky Online Tech Support Number

    ReplyDelete
  9. Your article is very unique and powerful for the new reader.

    HP Support Number +1-855-676-7123 is the ultimate destination for all your issues.

    HP Support Number

    HP Customer Care

    HP Technical Support

    HP Printer Support

    HP Laptop Support

    HP Printer Drivers Support

    HP Phone Number

    ReplyDelete
  10. Nice Post...

    People groups are utilizing Quicken to oversee and design their fiscal conduct effortlessly. One of the principle reasons why Quicken has turned out to be up front of individuals' lives today I because of the exceptional highlights it gives.


    Quicken Tech Support
    Quicken Technical Support
    Quicken Toll-Free Number

    Quicken Help and Support
    Quicken Customer Care
    Quicken Help Number
    Quicken Customer Service
    Quicken Phone Number

    Quicken Customer Support Number
    Quicken Support for MAC
    Quicken Windows Support
    Quicken Premier Support

    ReplyDelete
  11. Access Your Computer Update Your Security Software Fix ipad Disabled Issue Fix All iPad Errors Restart Your Device Plug Directly Into Your Computer Fix ipad Disabled Issue Update iTunes Update Your Computer
    Fix ipad Disabled Issue Switched Off Antivirus Firewall on Your Computer Update iTunes to the Latest Version Fix ipad Disabled Issue Check the Network Connection Verify Your Firewall Settings Fix ipad Disabled Issue

    ReplyDelete
  12. Check this out : https://www.skptricks.com/2018/07/working-with-textinput-in-react-native.html

    ReplyDelete
  13. Are you having trouble with your printer? Looking for printer technical support with proper customer care? Call Dial Printer Support at +1-888-621-0339 for quick and effective printer support customer care. Dial Printer Support
    Printer Technical Support

    ReplyDelete
  14. HP Pavilion Number
    HP Customer Support, download drivers, manuals and troubleshooting information for HP products, including pcs, laptops, desktops, printers, tablets, apps and services. Support for HP
    HP Support Printer

    ReplyDelete
  15. Brother Printer Support is team of well experienced experts who are capable to resolve your printer issue. If you face any problem with your printer like cable problem, blank screen issue, or your printer is not working properly then reach our experts by making a call at toll free number of Brother Support and get instant help.

    ReplyDelete
  16. Geek Squad Tech Support is a team of well experienced experts who are capable to repair your device in no time. If you are face any problem with your devices then there is only one stop solution that is Geek Squad Tech Support, so reach our experts and get instant help.

    ReplyDelete
  17. HP Printer Support is a group of experts who are quite efficient in giving the best of repair services. Reach for HP Printer Support help anytime, at their 24/7 available toll-free number.

    ReplyDelete
  18. HP Support is a help support group that deals with your broken HP devices. The experts available at this help group are well trained and educated and totally understands the urgency of a fixed device. The HP Support experts can be asked for help at their toll-free helpline, accessible worldwide.

    ReplyDelete
  19. AOL Tech Support Phone Number is a customer care helpline that is offered by one of world's best mail service provider. The experts at this toll-free helpline renders all your forget password, password recovery and other related issues. Reach them anytime of day or night whenever you need their help.

    ReplyDelete
  20. Brother Printer Support is team of well experienced experts who are capable to resolve your printer issue. If you face any problem with your printer like cable problem, blank screen issue, or your printer is not working properly then reach our experts by making a call at toll free number of Brother USA Support and get instant help.

    ReplyDelete
  21. HP Printer Support is a group of technical experts who fixes all your HP device issues. Issues like device is not working properly or need an update or other any type of problem are all taken care by the experts. Reach for their help at HP Printer Support helpline, accessible 24/7 across the globe.

    ReplyDelete
  22. Geek Squad Support is a device repair provider that is available globally. The experts at this repair desk are quite efficient and are well trained in dealing with any of customer technical issue. Call the Geek Squad Support specialists at their troubleshoot number, anytime you require.

    ReplyDelete
  23. Dell Printer Support is a group of experts who are quite efficient in providing the best of repair services against your broken Dell device. Feel free to call the experts at Dell Printer Support number that is especially designed for customer help from across the globe.

    ReplyDelete
  24. Epson Printer Support is a team of technical pros who are liable for any help you may require for your gadget or device. Reach for their help at Epson Printer Support number accessible 24/7.

    ReplyDelete
  25. Canon Printer Support is an organization that can be reached for technical help at any point of time. Do not hesitate and reach for their help at Canon Printer Support number, accessible 24/7.

    ReplyDelete
  26. Brother Printer Support is a group of experts who can be accessed from any corner of the world for technical help. Feel free to reach for expert help at Brother Printer Support for any big or small gadget query you come across.

    ReplyDelete
  27. Geek Squad Support is a device repair provider that is available globally. The experts at this repair desk are quite efficient and are well trained in dealing with any of customer technical issue. Call the Geek Squad Support specialists at their troubleshoot number, anytime you require.

    ReplyDelete
  28. Canon Printer Support is a team of experts who takes care of your canon device issue. If face any problem with your device like your device is crashed , device is not working properly or others then contact Canon Support and get instant help.

    ReplyDelete
  29. Acer Support is a team of well experienced experts who takes care of your acer devices. If you are facing any problem with your acer device like your device is crashed, device is not working properly or any other problem then contact toll free number Acer Tech Support and get instant help.

    ReplyDelete
  30. Dell Support is a team of experts who takes care of your dell device issue. If face any problem with your device like your device is crashed , device is not working properly or others then contact Dell Tech Support and get instant help.

    ReplyDelete
  31. HP Support is a team of experts who takes care of your hp device issue. If face any problem with your device like your device is crashed , device is not working properly or others then contact HP Tech Support and get instant help.

    ReplyDelete
  32. Thanks for sharing. i really appreciate it that you shared with us such a informative post
    kaspersky customer support number

    ReplyDelete
  33. www.Webroot.com/Safe Download
    www.Webroot.com/Safe
    www.Webroot.com -Safe

    Need to Have Advanced Technology internet Security software from Webroot safe Software company with the following Link webroot.com/safe that help to protect all device from virus, malware and other online threats.

    Webroot.com/Safe
    Webroot.com/Safe Download
    Webroot Support

    Webroot.com/Safe
    www.Webroot.com/Safe

    ReplyDelete
  34. Kaspersky Tech Support Phone Number

    Kaspersky Customer Support

    Kaspersky Customer Service

    Devices would be free from Virus, Malware, Trojan and other online threats
    Kaspersky Activation with the link activation.kaspersky.com gives you the Complete protection, like email protection, Banking Details Protections, Sensitive Information protection, important Software Protection, Get Instant Kaspersky Support or Call Kaspersky Customer Service

    http://www.kasperskysupports.us/

    Kaspersky Technical Support
    Kaspersky Support

    ReplyDelete
  35. Trendmicro BestBuy pc
    Trendmicro.com/bestbuypc
    www.Trendmicro.com/bestbuy

    Get TrendMicro Antivirus Activate with the link trendmicro.com/bestbuypc with Valid Product key. Get Instant Trend Micro support with the link trendmicro.com/bestbuypc
    http://www.trendmicrocombestbuypc.com/

    Trendmicro Support
    www.Trendmicro.com/bestbuypc
    Trendmicro.com/bestbuy
    www.Trendmicro.com best buy download

    ReplyDelete
  36. Aol email Support
    Aol Customer Service
    Aol Support Number

    Get Instant AOL Support for Technical Issue like Aol email Sign In Problem, Forgot Password, Aol Customer Service is the Highly Experts team, Call Aol Technical Support 24/7
    http://aoltech.support/

    Aol Support
    Aol Tech Support
    Aol tech support phone number
    Aol Customer Support

    ReplyDelete
  37. Trendmicro Support
    www.Trendmicro.com/bestbuypc
    Trendmicro.com/bestbuy
    www.Trendmicro.com best buy download

    Whenever you face any trouble against Trend Micro antivirus just feel free to visit trendmicro.com/bestbuy or to call on our Trend Micro technical support phone number for better services you deserve.
    http://www.trendmicrobestbuypc.com/

    Trendmicro BestBuy pc
    Trendmicro.com/bestbuypc
    www.Trendmicro.com/bestbuy

    ReplyDelete
  38. Webroot.com/Safe

    Webroot.com/Safe Download

    Webroot Support

    Get Advanced Webroot SecureAnywhere Security Software from the link webroot.com/safe, Or Get In Touch with Webroot Support

    http://webrootsafe-com.com/

    www.Webroot.com/Safe Download

    www.Webroot.com/Safe

    www.Webroot.com -Safe

    ReplyDelete
  39. Avira Support Number
    Thanks for the information. Avira is one of the best antivirus companies deals in providing various solutions to the client deals with the issues related to the threat faces while using the internet. Sometime a user might face issue error code 556 while using its services or products at that time he can take help using Avira support number. To get more information on Avira support number a user can visit our website.
    http://www.avirasupporttech.com/blog/avira-technical-support/how-to-fix-avira-product-error-code-556/

    ReplyDelete
  40. If you are facing any HP Printer errors or issues so contact our HP Printer Support Number 1844 881 6626 and get instant solution. Our HP Printer Support Number is available 24*7 and user can call from all over the world.
    HP Printer Phone Number

    ReplyDelete
  41. Thanks for the informative post. It is really helpful. Many a times users in windows 10 faces some error in Incredimail. It is recommended to visit our blog and get instant solution with 3 easy steps to fix this. There are more blog posts regarding different issues which you might face using Incredimail. If you face error in windows 10 then visit here How to Fix Incredimail Issues in windows 10

    ReplyDelete
  42. Thanks for the informative post it is very helpful really appreciated. Pogo Customer Care helps you in all possible error you face while playing our best online games. Pogo Support Number will help you instantly to solve your problems.

    ReplyDelete

More Posts

FOLLOW