<!-- login and sign up form-->
<div class="form">

  <!-- login -->
  <div class="login-form">
    <!-- cansel btn -->
    <a href="javascript:void(0);" class="login-cansel"> &times;</a>
    <!-- heading-->
    
    <strong>Log In</strong>
    <!-- inputs-->
    <form action="" method="post">
       <input type="text" name="username" placeholder="enter username"required>

      <input type="password" name="password" placeholder="enter password"required>
      <!-- submit -->
      <input type="submit" name="login" value="Log in">
    </form>
    <div class="form-btns">
      <!-- forget password and sign up btn -->
      <a href="javascript:void(0);" class="forget">Forget Your Password?</a>
      <a href="javascript:void(0);" class="sign-up">Create Account</a>
    </div>

  </div>



  <!-- sign up-->
  <div class="sign-up-form">
    <!-- cansel btn -->
    <a href="javascript:void(0);" class="sign-up-cansel"> &times;</a>
    <!-- heading-->
    <strong>Sign Up</strong>
    <!-- inputs-->
    <form action="" method="post">
      <input type="text" name="fullname" placeholder="enter Your Fullname" required>
      <input type="text" name="username" placeholder="enter username" required>
      <input type="email" name="email"placeholder="enter your email" required>
      <input type="number" name="phone"placeholder="enter your phoneNo" required>
      <input type="password" name="password" placeholder="enter password" required>
      <input type="password" name="confirm-password" placeholder="confirm  password" required>
      <!-- submit -->
      <input type="submit" name="SignUp"value="SignUp">
    </form>
    <div class="form-btns">
      <!-- forget password and sign up btn -->
      <a href="javascript:void(0);" class="already-account">Already Have Account?</a>

    </div>

  </div>
</div>
<!-- insert data into db -->
<?php
   //process the value from form and save in the SQLiteDatabase
   //check whether the submit btn is clicked or not
   if(isset($_POST['SignUp'])){
     // Button clicked
     //get the data from form
     $fullname = mysqli_real_escape_string($conn,$_POST['fullname']);
     $username = mysqli_real_escape_string($conn,$_POST['username']);
     $email = mysqli_real_escape_string($conn,$_POST['email']);
     $phone = mysqli_real_escape_string($conn,$_POST['phone']);
     $password = md5($_POST['password']); //pasword encryption with md5
     $confirmpassword = md5($_POST['confirm-password']); //pasword encryption with md5
     if($password==$confirmpassword){
       // sql to insert the data into the database
       $sql = "INSERT INTO tbl_user SET
          full_name = '$fullname',
          username = '$username',
          password = '$password',
          email = '$email',
          phone_number = '$phone'
       ";
       //execute query and save data in the database
       $res = mysqli_query($conn, $sql);
       //check whether the data is inserted or not and display appropriate message
        if($res==TRUE){
          // create session var to display message
         $_SESSION['add'] = "Account Created Successfully";
          //Redirect Page
         header('location:'.SITEURL.'shopping/login&sign-up.php');

        }else{
          // create session var to display message
          $_SESSION['failed'] = "Failed To Create Account";
          //Redirect Page
          header('location:'.SITEURL.'shopping/index.php');

        }
     }else{
       // create session var to display message
       $_SESSION['pwdmatch'] = "Password did not match";
       //Redirect Page
       header('location:'.SITEURL.'shopping/lgin&sign-up.php');

     }
   }
   ?>
   <?php
   //check whether the submit btn is clicked or not
    if (isset($_POST['login'])) {
      //process for login
      //1.get the data frm login form
      //$username = $_POST['username'];

      $raw_password = md5($_POST['password']);

      $username = mysqli_real_escape_string($conn, $_POST['username']);
      $password = mysqli_real_escape_string($conn, $raw_password);
      //2.sql to check whether the user with the username and password exists or not
      $sql1 = "SELECT * FROM tbl_user WHERE username='$username' AND password='$password'";
      //3.execute the querry
      $res1 = mysqli_query($conn, $sql1);
      //4.count rows to check whether the user exists or not
      $count1 = mysqli_num_rows($res1);
      if ($count1>0) {
        // user available and login success
        //$_SESSION['login'] = "<div class='success'>Login Successful.</div>";
      //  $_SESSION['user'] = $username;//to check whether the user is logged in or not and logout will unset it
        //redirect to the dashboard
      //  echo "yeap";
        //header('location:'.SITEURL.'shopping/');
      }else{
        //user not available and login failed
      //  $_SESSION['login'] = "<div class='error'>Login Failed.</div>";
        //redirect to the dashboard
        //header('location:'.SITEURL.'shopping/index.php');
      //  echo "nope";
      }
    }else{

      //error occurred during data proccessing
    }
    ?>
