Login, Signup and Logout Script using PHP and MySQL
Login, Signup or Logout these are the three things which you have
done in daily social networking sites.So, today post is related to that
one.Firstly,I will show you how the signup process work .In my project i
have taken three fields E-Mail, Username and password.We select email
as a primary key.
Database Design:
email varchar(100) PRIMARY KEY..username varchar(100)
password varchar(30)
Signup Form:
<form name="form1" action="index.php" method="POST">
<input type="email" name="email" placeholder="E-Mail" ><br>
<input type="text" name="uname" placeholder="Username" ><br>
<input type="password" name="pwd" placeholder="Password" ><br>
<input name="signup" type="submit" value="Sign Up">
<input type="email" name="email" placeholder="E-Mail" ><br>
<input type="text" name="uname" placeholder="Username" ><br>
<input type="password" name="pwd" placeholder="Password" ><br>
<input name="signup" type="submit" value="Sign Up">
Signup.php
In this PHP file i will show you some query and logics.
if($emai l =="" || $pwd =="" || $user =="" )
{
// this condition will check wheather three fields are empty it will show the POP up window
}
{
// this condition will check wheather three fields are empty it will show the POP up window
}
else
{
$user_avail=mysql_query("SELECT * FROM `signup` where email ='$email' ");
{
$user_avail=mysql_query("SELECT * FROM `signup` where email ='$email' ");
if(mysql_num_rows($user_avail)>0)
{
// If email and existed is match then " E-Mail ID is already Exist Please Try another.
}
else
{
$sql = mysql_query("INSERT INTO `vm`.`signup` (`email`, `username`, `pwd`) VALUES ('".$_POST['email']."', '".$_POST['username']."', '".$_POST['pwd']')."' ;");
{
$sql = mysql_query("INSERT INTO `vm`.`signup` (`email`, `username`, `pwd`) VALUES ('".$_POST['email']."', '".$_POST['username']."', '".$_POST['pwd']')."' ;");
//When all these conditions are true
then this statement will show "You have successfully registered login
with E-Mail & password Thankyou."
}
Login Form
This is the login form in which you have to enter the Valid email and password. When email and password is verify then you will go to the userprofile.php file.
<form action="loginscript.php" method="POST"><br>
<input id="box" type="email" name="name1" placeholder="E-Mail" required="required" ><br>
<input id="box" type="password" name="pwd" placeholder="Password" required="required" ><br>
<input id="btn" name="login "type="submit" value="Login">
</form>
<input id="box" type="email" name="name1" placeholder="E-Mail" required="required" ><br>
<input id="box" type="password" name="pwd" placeholder="Password" required="required" ><br>
<input id="btn" name="login "type="submit" value="Login">
</form>
Login.php
if(empty($email) || empty($pwd))
{
{
// ERROR MESSAGE :Please fill all fields
}
else
{
$sql = mysql_query("SELECT * FROM `signup` WHERE `email` = '$email' AND `pwd` = '$pwd';");
else
{
$sql = mysql_query("SELECT * FROM `signup` WHERE `email` = '$email' AND `pwd` = '$pwd';");
// Verify the email and password if they are OK
then it will executed next statement otherwise else statement.
if(mysql_num_rows($sql1)>0) // check user registered or not
{
while($row=mysql_fetch_array($sql1) )
{
$name = $_SESSION['name']=$row['username'];
$emails = $_SESSION['email']=$row['email'];
$pwd = $_SESSION['pwd']=$row['pwd'];
{
while($row=mysql_fetch_array($sql1) )
{
$name = $_SESSION['name']=$row['username'];
$emails = $_SESSION['email']=$row['email'];
$pwd = $_SESSION['pwd']=$row['pwd'];
header('location:userprofile.php'); // userprofile will show the a little profile to the authorised user
}
}
else
{
header('location:index.php');
// You have Wrong Username and Password
}
else
{
header('location:index.php');
// You have Wrong Username and Password
}
}
Comments
Post a Comment