![]() |
VOOZH | about |
In this article, we are going to check the credentials (username and password) entered by the user. If credentials are matched from the database entries, the user can enter into another page and if credentials are incorrect then it displays "Sorry Invalid Username and Password".
Pre-requisites: XAMPP server, Basics of HTML, CSS, PHP, MySQL.
Step 1: First, we must start the XAMPP server from the XAMPP control panel. XAMPP is bundled software.
Open XAMPP Control Panel and start Apache and MySQL services. In the XAMPP folder, go to htdocs folder and create a folder named check_username_pwd. We will keep all the files in the project folder. The files are index.php, login.php, check.php.
👁 ImageStep 2: Open the editor of your choice. Create a file named connect.php to make the database connection. The connection object is returned to the $conn variable. The name of the database is check.
connect.php: The function is used to connect the database.
Step 3: Create a database table.
CREATE TABLE register(
id int(10) AUTO_INCREMENT PRIMARY KEY,
firstname varchar(50),
lastname varchar(50),
username varchar(100),
year varchar(20),
mobile varchar(20),
password varchar(50)
);
A Database table is created with the name 'register'
👁 ImageStep 4: Create another file named index.php
This page is a PHP form that is used to insert a user's data to create a username and password. When data is inserted, an alert message "You Registered Successfully" is shown. This page contains a hyperlink login, on clicking on this user jumps to the login.php.
index.php:
Output:
👁 ImageThis is the output of the database after entering data through the registration form which is available on index.php.
👁 ImageStep 5: Create another file login.php. In this, we create a login form. When a user enters their username and password and if it is correct user jump on another page check.php.
login.php:
Output:
👁 ImageAnd if the username and password are not matched then it shows "Sorry Invalid Username and Password".
👁 ImageStep 6: Create another file check.php. This page is opened when the user enters the correct credentials and then clicks on the login button that means the Username and Password matched from the database.
Output:
👁 ImageStep 6: Run this project in Browser.
Output: