<?php
// var_dump($_POST);
// exit;

if(isset($_POST)){
include("config.php");

$firstName=mysqli_escape_string($conn,$_POST["firstName"]);
$lastName=mysqli_escape_string($conn,$_POST["lastName"]);
$email=mysqli_escape_string($conn,$_POST["emailaddress"]);
$phone=mysqli_escape_string($conn,$_POST["phone"]);
$gps=mysqli_escape_string($conn,$_POST["gps"]);
$region=mysqli_escape_string($conn,$_POST["region"]);
$constituency=mysqli_escape_string($conn,$_POST["constituency"]);
$password=mysqli_escape_string($conn,$_POST["password"]);
$cpassword=mysqli_escape_string($conn,$_POST["cpassword"]);


$query="SELECT * FROM users WHERE email='$email' AND status='Active'";
$data=mysqli_query($conn,$query);
$count=mysqli_num_rows($data);

// echo $count;
// exit;

if($count>0){
    $error="You are already in the system. Please login";
    header("location:signup.php?message=$error");
    exit;
    
}
elseif("$password" != "$cpassword"){
  $error="Passwords do not match";
  header("location:signup.php?message=$error");
  exit;
  
}
else{
  $password=md5($password);
  // echo $password;
  // exit;
  $transdate=date("Y-m-d");
  $query2="INSERT INTO users SET fname='$firstName',lname='$lastName',email='$email',phone='$phone',gps='$gps',region='$region',constituency='$constituency',password='$password',date_created='$transdate'";
  $data2=mysqli_query($conn,$query2);

    header("location:login.php");
    exit;
  
}
}
else{
  $error="You may have entered here wrongly";
  header("location:signup.php?message=$error");
  exit;
}

?>
