Create A Login Form Validation Using PHP And WAMP / XAMPP – Info PHP
Introduction
WAMP stands for Windows, Apache, MySQL and any one of PHP, Perl or Python. WAMP server is a local webserver for running the scripting language (PHP, Perl) and this is open source. XAMPP stands for Cross-Platform (X), Apache (A), Maria DB (M), PHP (P) and Perl (P). It is developed by Apache friends. It includes Apache and MySQL, FileZilla, Mercury, Tomcat and Maria DB.
Here, I am going to show how to create a login form validation, using PHP and XAMPP.
Requirements
- XAMPP/WAMP Server.
- Brackets (IDE).
- Little HTML, CSS and PHP knowledge.
Steps given below are required to be followed
Follow the steps to create a login form validation, using PHP and XAMPP. I have included the source code, which is given below.
Step 1
Open XAMPP Control Panel. Start Apache and MySQL Server.
Step 2
Open your Browser and then type http:// localhost or http://127.0.0.1. After you see XAMPP community page, make sure, if your Server is running or not.
Step 3
Open XAMPP Control Panel, followed by clicking MySQL admin. Now, create the database for the login validation form.
Step 4
To create the new database, click New.
Step 5
Put the database name, which you want. Here, the database name is user-registration, followed by clicking create.
Step 6
Go to SQL query tab, copy and paste the query given below. Click go. Afterwards, your table (my table name : person) is created successfully.
SQL query
- CREATE TABLE IF NOT EXISTS `login` (
- `username` varchar(200) NOT NULL,
- `password` varchar(200) NOT NULL,
- PRIMARY KEY (`username`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Step 7
Put your Webpage files into the destination folder. Default folder is c:/xampp/htdocs.
Step 8
Open the bracket(IDE) and create the login.php file. Copy the code given below and paste into login.php
Login -
- body{
- margin-top: 100px;
- margin-bottom: 100px;
- margin-right: 150px;
- margin-left: 80px;
- background-color: azure ;
- color: palevioletred;
- font-family: verdana;
- font-size: 100%
- }
- h1 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
- h3 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
-
CREATE REGISTRATION AND LOGIN FORM USING PHP AND MYSQL
“register.php”
>Register | “login.php”>LoginLogin Form
method=“POST”>- Username: “text” name=“user”>
- Password: “password” name=“pass”>
- “submit” value=“Login” name=“submit” />
- if(isset($_POST[“submit”])){
- if(!empty($_POST[‘user’‘pass’])) {
- $user=$_POST[‘user’];
- $pass=$_POST[‘pass’];
- $con=mysql_connect(‘localhost’,‘root’,”) or die(mysql_error());
- mysql_select_db(‘user_registration’) or die(“cannot select DB”);
- $query=mysql_query(“SELECT * FROM login WHERE username='”.$user.“‘ AND password='”.$pass.“‘”);
- $numrows=mysql_num_rows($query);
- if($numrows!=0)
- {
- while($row=mysql_fetch_assoc($query))
- {
- $dbusername=$row[‘username’];
- $dbpassword=$row[‘password’];
- }
- if
- {
- session_start();
- $_SESSION[‘sess_user’]=$user;
- header(“Location: member.php”);
- }
- } else {
- echo “Invalid username or password!”;
- }
- } else {
- echo “All fields are required!”;
- }
- }
- ?>
Step 9
Create the register.php file. Copy the code given below and paste into register.php.
register.php
Register -
- body{
- margin-top: 100px;
- margin-bottom: 100px;
- margin-right: 150px;
- margin-left: 80px;
- background-color: azure ;
- color: palevioletred;
- font-family: verdana;
- font-size: 100%
- }
- h1 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
- h2 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
-
CREATE REGISTRATION AND LOGIN FORM USING PHP AND MYSQL
-
“register.php”
>Register | “login.php”>Login -
Registration Form
method=“POST”>-
-
- Username: “text” name=“user”>
- Password: “password” name=“pass”>
- “submit” value=“Register” name=“submit” />
- if(isset($_POST[“submit”])){
- if(!empty($_POST[‘user’‘pass’])) {
- $user=$_POST[‘user’];
- $pass=$_POST[‘pass’];
- $con=mysql_connect(‘localhost’,‘root’,”) or die(mysql_error());
- mysql_select_db(‘user_registration’) or die(“cannot select DB”);
- $query=mysql_query(“SELECT * FROM login WHERE username='”.$user.“‘”);
- $numrows=mysql_num_rows($query);
- if($numrows==0)
- {
- $sql=“INSERT INTO login(username,password) VALUES(‘$user’,’$pass’)”;
- $result=mysql_query($sql);
- if($result){
- echo “Account Successfully Created”;
- } else {
- echo “Failure!”;
- }
- } else {
- echo “That username already exists! Please try again with another.”;
- }
- } else {
- echo “All fields are required!”;
- }
- }
- ?>
Register your username and password. Do not use the already used usernames.
Step 10
Create the logout.php file. Copy the code given below and paste into logout.php.
logout.php
- session_start();
- unset($_SESSION[‘sess_user’]);
- session_destroy();
- header(“location:login.php”);
- ?>
Step 13
Create the member.php file. Copy the code given below and paste into member.php.
member.php
- session_start();
- if(!isset($_SESSION[“sess_user”])){
- header(“location:login.php”);
- } else {
- ?>
Welcome -
- body{
- margin-top: 100px;
- margin-bottom: 100px;
- margin-right: 150px;
- margin-left: 80px;
- background-color: azure ;
- color: palevioletred;
- font-family: verdana;
- font-size: 100%
- }
- h2 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
- h1 {
- color: indigo;
- font-family: verdana;
- font-size: 100%;
- }
-
CREATE REGISTRATION AND LOGIN FORM USING PHP AND MYSQL
Welcome, =$_SESSION[‘sess_user’];?>! “logout.php”>Logout
- WE DO IT. SUCCESSFULLY CREATED REGISTRATION AND LOGIN FORM USING PHP AND MYSQL
- }
- ?>
Now, you need to click the logout.
Output
Now, check the database to check, whether our data was stored or not.
Here, we have successfully created a login form validation. Using PHP and WAMP/XAMPP, and we created and executed it. I will continue my next article to give you an in-depth knowledge about XAMPP, FilZilla and GitHub lessons.
Reference article
http://www.c-sharpcorner.com/article/install-and-configure-xampp-server-with-data-insert-into-database2/
Source code
https://github.com/GaneshanNT/Registration-and-login-validation-form
Article Prepared by Ollala Corp