<?php
    require_once 'adminnh/config.php';
    
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Fair Battle SignUp</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
    <script src='main.js'></script>
</head>

<body>
    <center>
    <div class="loginformclass">
        <h2> Sign In </h2>
        <form method="POST" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>">
             <center>
            <div class="input-field">
                <i class="glyphicon glyphicon-user" ></i>
                <input type="text" placeholder="Username" name="usernameid"/>
            </div>
            <div class="input-field">
                <i class="glyphicon glyphicon-envelope"></i>
                <input type="text" placeholder="Email" name="emailid"/>
            </div>
            <div class="input-field">
                <i class="glyphicon glyphicon-lock"></i>
                <input type="Password" placeholder="Password" name="passid"/>
            </div>
             <div class="input-field">
                <i class="glyphicon glyphicon-share"></i>
                <input type="text" placeholder="Refer Code (Optional)" value="<?php echo $_GET['refid']; ?>" name="refercode"/>
            </div>
            </center>
           <center> <button name="signin">Sign Up </button></center>
           <div class="form-link">
        I Allready have an account? <a href="signin.php">Sign In</a>
      </div>
        </form>
         
    </div>
   </center>
    <style>
        *{
            padding: 0;
            margin: 0;
          
            box-sizing: border-box;
            font-family: Poppins, Helvetica, "sans-serif";
            text-decoration: none;
        }
        body{
            text-align: center;
          
            background-color: #f2f4f6;
          
            
        }
        div.loginformclass{
   width: min-content;
border-radius: 5px;


text-align: center;
background-color: white;
box-shadow: 0px 5px 10px black;
        }
         div.loginformclass form{
         padding: 30px 60px;
         }
        div.loginformclass h2 {
            text-align: center;
            border-radius: 5px 5px 0px 0px;
            background-color: darkturquoise;
            padding: 12px 0px;
            color: white;
            margin-bottom: 10px;
          
        }
         
        div.loginformclass div.input-field{
            display: flex;
            flex-direction: row;
      margin-bottom: 10px;
        } 
        div.loginformclass div.input-field i{
            color: darkslategray;
            padding: 10px 10px;
            margin-right: 5px;
             border: 1px solid #ccc;
      border-radius: 3px;
           background-color: #f2f4f6;
          
        }
        
         div.loginformclass div.input-field input{
            background-color: #f2f4f6;
            padding: 10px;
           
            border: 1px solid #ccc;
      border-radius: 3px;
            width: 300px;
            padding-left: 15px;
        }
        div.loginformclass form button {
            width: 100%;
            background-color: darkturquoise;
            border: none;
            font-size: 18px;
             border: 1px solid #ccc;
      border-radius: 5px;
            margin: 15px 15px 0px 0px;
           
            color:  white;
            font-weight: 500;
            padding: 9px;


        }
        div.loginformclass form button:hover{
            background-color: skyblue;
             border: 1px solid darkturquoise;
      border-radius: 3px;
        }
          div.loginformclass form div.form-link {
            
        
            font-size: 16px;
            
            margin: 15px 15px 0px 0px;
           


        }
        
    </style>
    <?php
    function input_filter($data){
$data=trim($data);
$data=stripcslashes($data);
$data=htmlspecialchars($data);
return $data;
    }

if (isset($_POST['signin'])) {
 
    if(input_filter($_POST['emailid'])=="" or input_filter($_POST['passid'])=="" or input_filter($_POST['usernameid'])==""){
        
    $msg ="Please fill All field";
 echo '<script type="text/javascript">alert("' . $msg . '")</script>';

    }else{
   $emailid=input_filter($_POST['emailid']);
   $passid=input_filter($_POST['passid']);
   $usernameid=input_filter($_POST['usernameid']);
   $refercode=input_filter($_POST['refercode']);
   if($refercode==""){
       $refercode="no";
   }
   #scapeww
   $emailid=mysqli_real_escape_string($conn,$emailid);
   $passid=mysqli_real_escape_string($conn,$passid);
   $usernameid=mysqli_real_escape_string($conn,$usernameid);
   $refercode=mysqli_real_escape_string($conn,$refercode);
  $refercode=urlencode($refercode);
   $selchech=mysqli_query($conn,"SELECT * FROM userdataa Where email='$emailid'");
   
   if($selchech){
       
     $selchecuse=mysqli_query($conn,"SELECT * FROM userdataa Where username='$usernameid'");



if ($row = mysqli_fetch_assoc($selchech)<=0) {
     if($selchecuse){
      

if ($row = mysqli_fetch_assoc($selchecuse)<=0) {
     
     $mycode=urlencode($usernameid);
  
   $query =mysqli_query($conn,"INSERT INTO userdataa (username,email,Password,block,addmoney,winmoney,total_match,withdrawal,referby,refercode,refa,refb) Values ('$usernameid','$emailid','$passid','0','0','0','0','0','$refercode','$mycode','0','0')");

 if($query){
     
      session_start();
      $_SESSION['usernameid'] = $usernameid;
       $_SESSION['emailid'] = $emailid;
header("Location: fairb/index.php");
 }else{
       die("Connection failed: " . mysqli_connect_error());
 }
    
  }else{
    
     $msgem="Incorect Username";
    echo '<script type="text/javascript">alert("' . $msgem . '")</script>'; 
  }
  }
    
    
  }else{
     $msgem="Incorect Email";
    echo '<script type="text/javascript">alert("' . $msgem . '")</script>';   
     
 
  

}
}
}
}


?>
</body>
</html>