PHP PDO Tutorials: PHP Registration and Login form Using database

PHP PDO Tutorials PHP Registration and Login form Using database HINDI URDU



Create Db of Name "Mujahid"

After that you need to create table:


CREATE TABLE `users` (
`id` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 25 ) NOT NULL ,
`email` VARCHAR( 25 ) NOT NULL ,
`pass` VARCHAR( 25 ) NOT NULL,
`date` VARCHAR( 25 ) NOT NULL,
`month` VARCHAR( 25 ) NOT NULL,
`year` VARCHAR( 25 ) NOT NULL
)

Create first file name write as "Index.php"




<?php
session_start();
try{
$con = new PDO ("mysql:host=localhost;dbname=mujahid","root","");
if(isset($_POST['signup'])){
 $name = $_POST['name'];
 $email = $_POST['email'];
 $pass = $_POST['pass'];
 $date = $_POST['date'];
 $month = $_POST['month'];
 $year = $_POST['year'];
 
 $insert = $con->prepare("INSERT INTO users (name,email,pass,date,month,year)
values(:name,:email,:pass,:date,:month,:year) ");
$insert->bindParam(':name',$name);
$insert->bindParam(':email',$email);
$insert->bindParam(':pass',$pass);
$insert->bindParam(':date',$date);
$insert->bindParam(':month',$month);
$insert->bindParam(':year',$year); 
$insert->execute();
}elseif(isset($_POST['signin'])){
 $email = $_POST['email'];
 $pass = $_POST['pass'];
 
 $select = $con->prepare("SELECT * FROM users WHERE email='$email' and pass='$pass'");
 $select->setFetchMode(PDO::FETCH_ASSOC);
 $select->execute();
 $data=$select->fetch();
 if($data['email']!=$email and $data['pass']!=$pass)
 {
  echo "invalid email or pass";
 }
 elseif($data['email']==$email and $data['pass']==$pass)
 {
 $_SESSION['email']=$data['email'];
    $_SESSION['name']=$data['name'];
header("location:profile.php"); 
 }
 }
}
catch(PDOException $e)
{
echo "error".$e->getMessage();
}
?>

<div style="width:500px ; height:600px; float:left;">
<div style="padding:85px;">
<h1>Create Account Here</h1>
<form method="post">
<input type="text" name="name" placeholder="User Name"><br><br>
<input type="text" name="email" placeholder="example@example.com"><br><br>
<input type="text" name="pass" placeholder="**********"><br><br>
<select name="date">
<option value="DATE">DATE</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
</select>
<select name="month">
<option value="MONTH">MONTH</option>
<option value="JAN">JAN</option>
<option value="FEB">FEB</option>
<option value="MAR">MAR</option>
</select>
<select name="year">
<option value="YEAR">YEAR</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
</select><br><br>
<input type="submit" name="signup" value="SIGN UP">
</form>
</div>
</div>
<div style="width:500px ; float:right; height:600px;">
<div style="padding:85px;padding-right:200px;">

<h1>Log In Here</h1>
<form method="post">
<input type="text" name="email" placeholder="example@example.com"><br><br>
<input type="text" name="pass" placeholder="**********"><br><br>
<input type="submit" name="signin" value="SIGN IN">
</div>
</div>


Create Profile.php file 



<?php  session_start();
if(empty($_SESSION['email']))
{
 header("location:index.php");
}

?>

WELCOME :<?php echo $_SESSION['name']; ?>

<a href="logout.php">Logout</a>


Create logout.php file



<?php
session_start();
session_destroy();

header("location:index.php");

?>

3 comments:

  1. Hi, Your article is Amazing you know your article is useful for me and everyone and and thanks for sharing information tq PHP training institute in Delhi

    ReplyDelete
  2. Excellent website! I adore how it is easy on my eyes it is. I am questioning how I might be notified whenever a new post has been made. Looking for more new updates. Have a great day! hotmail

    ReplyDelete

Pages