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', '[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 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><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 src="https://www.chiphost.org/blog/wp-content/uploads/2020/09/My-Photo-150x150.jpg" width="80" height="80" alt="Saurav Sen" class="avatar avatar-80 wp-user-avatar wp-user-avatar-80 alignnone photo" /></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" role="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>16 Free Responsive Bootstrap Business Templates 2021</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>(adsbygoogle = window.adsbygoogle || []).push({});</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 noreferrer" data-wpel-link="internal">Contact </a> | <a href="https://www.chiphost.org/blog/about/" target="_blank" rel="noopener nofollow noreferrer" data-wpel-link="internal">About Us</a> | <a href="https://www.chiphost.org/blog/privacy/" target="_blank" rel="noopener nofollow noreferrer" 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 noreferrer external" data-wpel-link="external">Facebook</a> | <a href="https://twitter.com/chiphost" target="_blank" rel="noopener nofollow noreferrer external" data-wpel-link="external">Twitter</a> | <a href="https://www.chiphost.org/blog/sitemap_index.xml" target="_blank" rel="noopener noreferrer" 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"> © 2021 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"><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 href="javascript:void(0)" style="color:#333333;" class="wt-cli-ccpa-opt-out" data-wpel-link="internal">Do not sell my personal information</a>.</div></div><div class="cli-bar-btn_container"><a role='button' tabindex='0' class="medium cli-plugin-button cli-plugin-main-button cli_settings_button" style="margin:0px 10px 0px 5px;" >Settings</a><a role='button' tabindex='0' 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" style="display:inline-block; ">Accept</a></div></div></span></div><div id="cookie-law-info-again" style="display:none;"><span id="cookie_hdr_showagain">Privacy & Cookies Policy</span></div><div class="cli-modal" 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" 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"><p>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.</p></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"><p>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.</p></div></div></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 type='text/javascript' src='https://www.chiphost.org/blog/wp-content/themes/xmag/js/main.js'></script> <script type='text/javascript' src='https://www.chiphost.org/blog/wp-includes/js/wp-embed.min.js'></script> </body></html><script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>