One page login form using PHP MySQL Select Query

This login script provides 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 an 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 the SQL tab and put this sql quarry given below and then click the GO button.

INSERT INTO `member` (`id`, `username`, `password`, `client_status`) 
VALUES ('1', 'saurav@gmail.com', '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 a 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 executed. Condition is to 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 deactivated client_status value then logging will not be successful.


include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$myusername=$_REQUEST["username"];
$mypassword=$_REQUEST["password"];
{
$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);
    if($rows!="")
    {
	    $_SESSION['name'] = $myusername;
            // Redirect user to dash.php
	    header("Location:dash.php?u=$myusername");
         }
         else
         {
	   header('Location:login.php');
	   
	   }
}
}
?>




Untitled Document</title>
</head>
<body data-rsssl=1>
<form action="" method="post">
<input type="text" name="username" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="submit" />
</form>
</body>
</html></pre><p><strong>config.php</strong></p><pre class="wp-block-syntaxhighlighter-code"><?php>
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'domaincom_client');
define('DB_PASSWORD', 'jj888iik9ij8@');
define('DB_DATABASE', 'domaincom_db');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?></pre><p><strong>logout.php</strong></p><pre class="wp-block-syntaxhighlighter-code"><?php>
session_start();
if(session_destroy())
{
header("Location: login.php");
}
?></pre><p></p><div class="crp_related     crp-text-only"><h3>Related Posts:</h3><ul><li><a href="https://www.chiphost.org/blog/how-to-create-a-login-form-in-html-css-with-source-code/" class="crp_link post-144" data-wpel-link="internal"><span class="crp_title">How To Create a Login Form in HTML CSS with Source Code</span></a></li><li><a href="https://www.chiphost.org/blog/login-ftp/" class="crp_link post-67" data-wpel-link="internal"><span class="crp_title">How to login FTP | FTP login help details | File Transfer…</span></a></li><li><a href="https://www.chiphost.org/blog/how-to-insert-data-mysql-database-using-php/" class="crp_link post-346" data-wpel-link="internal"><span class="crp_title">How to Insert Data MySQL Database Using PHP</span></a></li><li><a href="https://www.chiphost.org/blog/insert-data-mysql-database-using-php-pdo-method/" class="crp_link post-477" data-wpel-link="internal"><span class="crp_title">Insert Data MySQL Database Using PHP PDO Method</span></a></li></ul><div class="crp_clear"></div></div></div><footer class="entry-footer"> <span class="cat-links"><span class="icon-folder"></span> Category: <a href="https://www.chiphost.org/blog/category/tutorials/" rel="category tag" data-wpel-link="internal">Tutorials</a></span><span class="tags-links"><span class="icon-tag"></span> Tag: <a href="https://www.chiphost.org/blog/tag/coding/" rel="tag" data-wpel-link="internal">Website Coding</a></span></footer></article><div class="author-info clear"><div class="author-avatar"> <img data-del="avatar" src='https://www.chiphost.org/blog/wp-content/uploads/2020/09/My-Photo-150x150.jpg' class='avatar pp-user-avatar avatar-80 photo ' height='80' width='80'/></div><div class="author-description"><h3 class="author-title">Saurav Sen</h3><div class="author-bio"> Hi, I am a professional blogger and web developer. So I also share experiences with web development tutorials and blogging tips and including writing about HTML, CSS, JavaScript, Jquery, Ajax, PHP, and MySQL. <a class="author-link" href="https://www.chiphost.org/blog/author/chiphost/" rel="author" data-wpel-link="internal"> View all posts by Saurav Sen </a></div></div><div class="author-social"></div></div><nav class="navigation post-navigation" aria-label="Posts"><h2 class="screen-reader-text">Post navigation</h2><div class="nav-links"><div class="nav-previous"><a href="https://www.chiphost.org/blog/insert-data-mysql-database-using-php-pdo-method/" rel="prev" data-wpel-link="internal">Previous Post<span>Insert Data MySQL Database Using PHP PDO Method</span></a></div><div class="nav-next"><a href="https://www.chiphost.org/blog/bootstrap-business-templates/" rel="next" data-wpel-link="internal">Next Post<span>14 Free Responsive Bootstrap Business Templates</span></a></div></div></nav></main></div><div id="secondary" class="sidebar widget-area  widget-grey" role="complementary"><aside id="text-3" class="widget widget_text"><div class="textwidget"><ul><li><a href="https://www.chiphost.org/blog/category/design/" data-wpel-link="internal">Theme & Templates</a></li><li><a href="https://www.chiphost.org/blog/tag/wordpress/" data-wpel-link="internal">WordPress Theme</a></li><li><a href="https://www.chiphost.org/blog/category/website-templates/" data-wpel-link="internal">Website Templates</a></li><li><a href="https://www.chiphost.org/blog/category/theme/" data-wpel-link="internal">Theme Download</a></li><li><a href="https://www.chiphost.org/blog/category/howto/" data-wpel-link="internal">See Interaction</a></li><li><a href="https://www.chiphost.org/blog/category/tutorials/" data-wpel-link="internal">Read Tutorials</a></li></ul><p> </p><p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br /> <br /> <ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-1176293220757109" data-ad-slot="1370247567" data-ad-format="auto" data-full-width-responsive="true"></ins><br /> <script id="wpsolr-15">window.addEventListener("wpsolr", function(){wpsolr(15, "inline", null)});</script></p></div></aside><aside id="text-4" class="widget widget_text"><h3 class="widget-title"><span>Most Popular</span></h3><div class="textwidget"><p>How do create a website</p><p><a href="https://www.chiphost.org/blog/install-wordpress/" data-wpel-link="internal">How to install WordPress</a></p><p><a href="https://www.chiphost.org/blog/google-drive-downloader/" rel="noopener" data-wpel-link="internal">Download Google Drive big Files</a></p><p><a href="https://www.chiphost.org/blog/download-and-install-google-chrome/" rel="noopener" data-wpel-link="internal">Download or Install Google Chrome</a></p></div></aside></div></div></div><footer id="colophon" class="site-footer" role="contentinfo"><div class="footer widget-area" role="complementary"><div class="container"><div class="row"><div class="col-4" id="footer-area-left"><aside id="text-7" class="widget widget_text"><div class="textwidget"><p><a href="https://www.chiphost.org/blog/contact/" target="_blank" rel="noopener nofollow" data-wpel-link="internal">Contact </a> | <a href="https://www.chiphost.org/blog/about/" target="_blank" rel="noopener nofollow" data-wpel-link="internal">About Us</a> | <a href="https://www.chiphost.org/blog/privacy/" target="_blank" rel="noopener nofollow" data-wpel-link="internal">Privacy</a></p></div></aside></div><div class="col-4" id="footer-area-center"></div><div class="col-4" id="footer-area-right"><aside id="text-6" class="widget widget_text"><div class="textwidget"><p><a href="https://www.facebook.com/chiphost/" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external">Facebook</a> | <a href="https://twitter.com/chiphost" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external">Twitter</a> | <a href="https://www.chiphost.org/blog/sitemap_index.xml" target="_blank" rel="noopener" data-wpel-link="internal">SiteMap</a></p></div></aside></div></div></div></div><div class="footer-copy"><div class="container"><div class="row"><div class="col-6"><div class="site-info"> © 2023 Chiphost Blog <span class="sep">/</span> <a href="https://wordpress.org/" data-wpel-link="external" target="_self" rel="nofollow external noopener noreferrer">Powered by WordPress</a> <span class="sep">/</span> <a href="https://www.designlabthemes.com/" rel="nofollow external noopener noreferrer" data-wpel-link="external" target="_self">Theme by Design Lab</a></div></div><div class="col-6"></div></div></div></div></footer></div><div id="cookie-law-info-bar" data-nosnippet="true"><span><div class="cli-bar-container cli-style-v2"><div class="cli-bar-message">We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.</br><div class="wt-cli-ccpa-element"> <a style="color:#333333" class="wt-cli-ccpa-opt-out">Do not sell my personal information</a>.</div></div><div class="cli-bar-btn_container"><a role='button' class="medium cli-plugin-button cli-plugin-main-button cli_settings_button" style="margin:0px 10px 0px 5px">Settings</a><a role='button' data-cli_action="accept" id="cookie_action_close_header" class="medium cli-plugin-button cli-plugin-main-button cookie_action_close_header cli_action_button wt-cli-accept-btn">Accept</a></div></div></span></div><div id="cookie-law-info-again" data-nosnippet="true"><span id="cookie_hdr_showagain">Privacy & Cookies Policy</span></div><div class="cli-modal" data-nosnippet="true" id="cliSettingsPopup" tabindex="-1" role="dialog" aria-labelledby="cliSettingsPopup" aria-hidden="true"><div class="cli-modal-dialog" role="document"><div class="cli-modal-content cli-bar-popup"> <button type="button" class="cli-modal-close" id="cliModalClose"> <svg class="" viewBox="0 0 24 24"><path d="M19 6.41l-1.41-1.41-5.59 5.59-5.59-5.59-1.41 1.41 5.59 5.59-5.59 5.59 1.41 1.41 5.59-5.59 5.59 5.59 1.41-1.41-5.59-5.59z"></path><path d="M0 0h24v24h-24z" fill="none"></path></svg> <span class="wt-cli-sr-only">Close</span> </button><div class="cli-modal-body"><div class="cli-container-fluid cli-tab-container"><div class="cli-row"><div class="cli-col-12 cli-align-items-stretch cli-px-0"><div class="cli-privacy-overview"><h4>Privacy Overview</h4><div class="cli-privacy-content"><div class="cli-privacy-content-text">This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.</div></div> <a class="cli-privacy-readmore" aria-label="Show more" role="button" data-readmore-text="Show more" data-readless-text="Show less"></a></div></div><div class="cli-col-12 cli-align-items-stretch cli-px-0 cli-tab-section-container"><div class="cli-tab-section"><div class="cli-tab-header"> <a role="button" tabindex="0" class="cli-nav-link cli-settings-mobile" data-target="necessary" data-toggle="cli-toggle-tab"> Necessary </a><div class="wt-cli-necessary-checkbox"> <input type="checkbox" class="cli-user-preference-checkbox"  id="wt-cli-checkbox-necessary" data-id="checkbox-necessary" checked="checked"  /> <label class="form-check-label" for="wt-cli-checkbox-necessary">Necessary</label></div> <span class="cli-necessary-caption">Always Enabled</span></div><div class="cli-tab-content"><div class="cli-tab-pane cli-fade" data-id="necessary"><div class="wt-cli-cookie-description"> Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.</div></div></div></div><div class="cli-tab-section"><div class="cli-tab-header"> <a role="button" tabindex="0" class="cli-nav-link cli-settings-mobile" data-target="non-necessary" data-toggle="cli-toggle-tab"> Non-necessary </a><div class="cli-switch"> <input type="checkbox" id="wt-cli-checkbox-non-necessary" class="cli-user-preference-checkbox"  data-id="checkbox-non-necessary" checked='checked' /> <label for="wt-cli-checkbox-non-necessary" class="cli-slider" data-cli-enable="Enabled" data-cli-disable="Disabled"><span class="wt-cli-sr-only">Non-necessary</span></label></div></div><div class="cli-tab-content"><div class="cli-tab-pane cli-fade" data-id="non-necessary"><div class="wt-cli-cookie-description"> Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.</div></div></div></div></div></div></div></div><div class="cli-modal-footer"><div class="wt-cli-element cli-container-fluid cli-tab-container"><div class="cli-row"><div class="cli-col-12 cli-align-items-stretch cli-px-0"><div class="cli-tab-footer wt-cli-privacy-overview-actions"> <a id="wt-cli-privacy-save-btn" role="button" tabindex="0" data-cli-action="accept" class="wt-cli-privacy-btn cli_setting_save_button wt-cli-privacy-accept-btn cli-btn">SAVE & ACCEPT</a></div></div></div></div></div></div></div></div><div class="cli-modal-backdrop cli-fade cli-settings-overlay"></div><div class="cli-modal-backdrop cli-fade cli-popupbar-overlay"></div> <script id="wpsolr-16">window.addEventListener("wpsolr", function(){wpsolr(16, "inline", null)});</script> <script id="wpsolr-17">window.addEventListener("wpsolr", function(){wpsolr(17, "url", "https://www.chiphost.org/blog/wp-content/plugins/wp-user-avatar/assets/js/frontend.min.js")});</script> <script id="wpsolr-18">window.addEventListener("wpsolr", function(){wpsolr(18, "url", "https://www.chiphost.org/blog/wp-content/themes/xmag/js/main.js")});</script> <script id="wpsolr-19">window.addEventListener("wpsolr", function(){wpsolr(19, "inline", null)});</script> </body></html>