<?php
session_start();
require('connectdb.php');
require_once 'class.user.php';


$reg_user = new User();

if(isset($_POST['email'])){


$email = $_POST['email'];
$username = $_POST['username'];
$fname = $_POST['f_name'];
$lname = $_POST['l_name'];
$country = $_POST['country'];
$state = $_POST['country'];
$city = $_POST['city'];
$password = $_POST['pw'];
$confirm = $_POST['pw2'];
$gender = $_POST['gender'];
$wallet = $_POST['btc'];
$question = $_POST['SQ'];
$answer = $_POST['SA'];

$date = date('Y-m-d h:i:s');
$status = 0;

$stmt = $reg_user->runQuery("SELECT * FROM members WHERE email=:email");
  $stmt1 = $reg_user->runQuery("SELECT * FROM members WHERE username=:username");
  $stmt->execute(array(":email"=>$email));
  $stmt1->execute(array(":username"=>$username));
  $row = $stmt->fetch(PDO::FETCH_ASSOC);
  $row1 = $stmt1->fetch(PDO::FETCH_ASSOC);
  
  
  if($stmt->rowCount() > 0 || $stmt1->rowCount() > 0)
  {
    echo "
           Email or Username already exists! Please, try another one!
        
        ";
  }
  else
  {
    if($reg_user->create($fname,$lname,$username,$email,$gender,$country,$state,$city,$wallet,$question,$answer,$password,$date,$status))
    {     
      $id = $reg_user->lasdID();  


      $_SESSION['email'] = $email;

      echo 'yes';
     
    }
    else
    {
      echo "Sorry , Query could no execute...";
    }
}

}
