Login system using php and mysql

PHP/MYSQL LOGIN SYSTEM


● System contains 3 php files
    1 - login.php
    2 - welcome.php
    4 - config.php
STEPS TO IMPLEMENT
    1 - create database "login" in mysql
    2 - create table -
         users( id, name, email, password )
    3 - insert some rows in this table
    4 - now create 3 files
         login.php, welcome.php, config.php
         As follows
Config.php
<?php
$con =mysql_connect('localhost','user','pw');
mysql_select_db("login", $con);
?>
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Login.php
<?php
    session_start ();
    If (isset ($_SESSION ['user']))
    {
         header ("location:welcome.php");
    }
    include ("config.php");
?>
<form method="post">
  Email : <input type="email" name="em">
  <br>
  <input type="password" name="pw">
  <br>
  <input type="submit" name="login"
    value="login">
</form>
<?php
    If (isset ($_POST ['login']))
    {
          $em=$_POST['em'];
          $pw=$_POST['pw'];
          $sql="SELECT * FROM user
                      WHERE email='$em' &
                      password='$pw' ";
          $qry=mysql_query($sql);
          $count=mysql_num_rows ($qry);
      
          If($count==1)
           {
               $_SESSION ['user']=$em;
               header ("location:welcome.php");
            }
             else
             {
                 echo "invalid login";
              }
    }
?>
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Welcome.php
<?php
session_start();
include ("config.php:);
If (!(isset ($_SESSION ['user']))
{
   header("location:login.php");
}
$em=$_SESSION['user'];
 $sql="SELECT * FROM user WHERE
email='$em' ";
 $qry=mysql_query($sql);
$row=mysql_fetch_assoc ($qry);
echo "welcome : ".$row['name'];
?>

Comments