One page login form using PHP MySQL Select Query

This login script provide the authentication for our web page. This is one page Php login Script using PHP MySQL Select Query. Click the submit button then execute this php script.

PHP MySQL Select Query

The basic syntax of the select Query. Example is given below

SELECT column1_name, column2_name, column3_name FROM table_name;

To select all columns from the table using * character.

SELECT * FROM table_name

This is real life MySql database structure. ID is a AUTO_INCREMENT column. It is count number of table rows. The username column is for the username. The password column is for the password and client_status is for the client_status.

database structure

How to make this database

Please see follow the number.

create mysql database

How to insert data in the Mysql database table

Open MySql database select table and then click SQL tab and put this sql quarry given below and then click GO button.

INSERT INTO `member` (`id`, `username`, `password`, `client_status`) 
VALUES ('1', '[email protected]', '123456', 'active ');
PHP MySQL Select Query

Our database is created and show database value. ID,username,password,client_status is a table Field name.

MySQL Database

PHP Login Form with Sessions

This is login.php page. First include config.php. config.php is a database connection page. Next start Session variables. This Session store individual client information. Next if condition. User press the login form submit button then this condition is execute. Condition is catch this server value $myusername,$mypassword PHP variables and execute PHP MySQL Select Query. When all three condition is match then login now be successful. my_client2 is mysql database table name. This $rows value is not empty then redirect dash.php otherwise redirect login.php. If you have deactivate client_status value then logging will not be successful.

$query = "SELECT * FROM my_client2 WHERE username='$myusername'AND passcode='$mypassword' AND client_status='active'";
    $result = mysqli_query($db,$query) or die(mysql_error());
    $rows = mysqli_num_rows($result);
	    $_SESSION['name'] = $myusername;
            // Redirect user to dash.php

<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<form action="" method="post">
<input type="text" name="username" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="submit" />


define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'domaincom_client');
define('DB_PASSWORD', '[email protected]');
define('DB_DATABASE', 'domaincom_db');


header("Location: login.php");