PHP MySQL Login Form: In this tutorial you will know that how to create a login form in html coding and how to connect with mysql server using PHP coding. This is a fundamental example of PHP n MySQL connectivity and it is used in almost every website for login purpose.
PHP MySQL Login Form: In this tutorial you will know that how to create a login form in html coding and how to connect with mysql server using PHP coding. This is a fundamental example of PHP n MySQL connectivity and it is used in almost every website for login purpose.Login Form using PHP and MySQL:
In any website generally it is mandatory to have a login form to keep your data secure. In this regard we need to have a table which keeps the user-id and respective password, in this tutorial we will study how to create a login form, connect with the database server and login.
First of all we need to create a table which will store the username and password.
create table user (username varchar(10), password varchar(10));

After that we will store few data into it:
insert into user
values('roseindia','roseindia');
similarly you can insert more values.
Code:
userLogin.html
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><
html><
head><
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><
title>Insert title here</title></
head><
body > <form method="post" action="userLogin.php" ></body> </
Output:

userLogin.php
<?php
$f_usr
= $_POST["userid"];$f_pswd
= $_POST["password"];$con=mysql_connect("localhost","root","");
if(! $con) {
}
mysql_select_db("roseindia",$con);
$result
=mysql_query("select * from user");while
($row=mysql_fetch_array($result)){
if($row["username"]==$f_usr && $row["password"]==$f_pswd) echo"Welcome";echo
"Sorry";}
?>
If the username and password both are correct then output will be:
Welcome
If any one of the field or both are incorrect then the output will be:
Sorry